Posts Tagged ‘postgres’
Postgres – cheat sheet
Setup (http://www.postgresql.org/docs/8.1/static/tutorial.html):
If you use MacPorts to do your postgres install then remember to append the path for the postgres install location to your PATH variable in the .bash_login file (this should be in your home directory). In my case it is:
“/opt/local/lib/postgresql81/bin”
- Setting up Postgres
- mkdir data (this is for the database file)
- initdb -D data (initialize the database file)
- Starting the database
- pg_ctl -D . start -l logfile (remember here the . signifies the present directory. Your log file may not be here)
- Stopping the database
- pg_ctl -D . stop -l logfile
- For more information on pg_ctl type:
- pg_ctl –help
- Using PSQL (type psql –help)
- To list all the databases: psql -l
- Default HOSTNAME: “localhost”
- Default PORT: “5432″
- Default NAME: “the username you used to set it up”
- Create your DB:
- createdb dbname
- Delete your DB:
- dropdb dbname
- Connect to the database using:
- psql dbname
- psql \du (this will list the users in your database)
- Creating a user:
- create user username password pass
- psql \du (this will list the user in your database)
- Give the user all rights for the database you created:
- grant all on dbname.* to username
- Show all the tables in a database:
- \dt
Also, something else that might be helpful is pgAdmin III. It is a gui for postgres.