Home > computing > PostgreSQL Very Basic Cheatsheet

PostgreSQL Very Basic Cheatsheet

(Wrote this a few weeks ago when I knew nothing. Indented into my brain now. Should have published earlier or just trashed the post as it seems too simple now. So instead I’ll update it when I find out some new neat tricks.)

List of databases:
$ psql -l

To open one of them,
$ psql MyDatabase

To see what is in the database (list of relations),
mydb=# \d

To examine a specific table,
mydb=# \d TableName

Can execute SQL,
mydb=# select * from Table;

Can edit SQL in an editor from within PSQL,
mydb=# \e

To quit,
mydb=# \q

To load a schema from a file
$ psql mydb -f /home/foo/bar

Also from the shell,
$ pg_dump -O myDB > file
(-O means no ownership information is outputed)

On my server configuration (default for ubuntu) you can restart the PostgreSQL service using,
$ sudo /etc/init.d/postgresql-8.3 restart

Categories: computing Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

I don't read comments anymore due to an increase in spam comments. If you want to get in touch please send me an email (see tianjara.net for details).

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: