tring tring – research log

research log

Posts Tagged ‘postgres

Postgres – cheat sheet

without comments

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”

  1. Setting up Postgres
    1. mkdir data (this is for the database file)
    1. initdb -D data (initialize the database file)
  2. Starting the database
    1. pg_ctl -D . start -l logfile (remember here the . signifies the present directory. Your log file may not be here)
  3. Stopping the database
    1. pg_ctl -D . stop -l logfile
  4. For more information on pg_ctl type:
    1. pg_ctl –help
  5. Using PSQL (type psql –help)
    1. To list all the databases: psql -l
  6. Default HOSTNAME: “localhost”
  7. Default PORT: “5432″
  8. Default NAME: “the username you used to set it up”
  9. Create your DB:
    1. createdb dbname
  10. Delete your DB:
    1. dropdb dbname
  11. Connect to the database using:
    1. psql dbname
    2. psql \du (this will list the users in your database)
  12. Creating a user:
    1. create user username password pass
    2. psql \du (this will list the user in your database)
  13. Give the user all rights for the database you created:
    1. grant all on dbname.* to username
  14. Show all the tables in a database:
    1. \dt

Also, something else that might be helpful is pgAdmin III. It is a gui for postgres.

Written by tringer

January 8, 2008 at 9:06 pm

Posted in Uncategorized

Tagged with