Friday, July 6

Learning postgresql pt2

This actually should be the first part; because now Id like to look into db administration and management, etc.

Postgresql also use client/server model. In order to manipulate any database or its tables, we have to first connect to the database using client applications, for example, psql. This is an interactive query tool in terminal. We use it to connect to our database:

-U option provides the username that we would like to use to connect to the database. After issuing this the terminal will ask password corresponding to the username. By default, when freshly installed, postgresql will create several predefined stuff for you to get started: superuser role postgres, database postgres, etc. Therefore for the first time you could use postgres to connect to the database. After you login, the prompt will change into the name of the database you are currently logged into, now you could use various commands to know about this database.

\d displays all the tables in this database, \du displays all roles across all database clusters: in postgresql, every role acts like an account, with different privileges. Use \q to quit the interactive client. For more usage, please refer to the official manual.

I remember I come across some problems logging into the database as the default superuser, but I cannot remember exactly what the problem is. Anyway, you could always log in as the default superuser as long as you use sudo. To create your own username and password using createuser. Also createdb and dropdb is other commands that are pretty self-explanatory. Note all these commands are issued in the terminal before logging into psql.

No comments:

Post a Comment