########################################################################### # PostgreSQL Notes # # Anuradha Weeraman, 25 February 2000 # # $Id: postgresql.txt,v 1.1 2004/06/02 21:17:54 anuradha Exp $ # ########################################################################### This is what i have got from reading /usr/doc/postgresql-doc/indexpage.html as far as i see, pgsql looks to be a really stable rdbms very much similar to MySQL but a bit more resource hungry but much more reliable. * to start the pgsql server, one has to start the postmaster, which can be done on debian by '/etc/init.d/postgresql start' * psql is the client that can be used to query the db psql [-d dbname] [-h host] [-f filename] [-l] [-o filename] [-p port] [-q] [-s] [-u] [-x] -f : can be used to specify file to get sql input from -l : used to display the databases, must be used with -u -o : to sent output to a file -q : quiet mode, good for shell scripts -s : single-step-mode -u : prompt for username and password -x : turn on extended row format some psql commands are : \connect dbname username \copy table {FROM | TO} filename \d [table] - list tables in database or if table is specified, list the fields of the table \da - list aggregates \dd - list the description of the table, table.column, type, operator or aggregate. \df - list functions \di - list only indexes \do - list only operators \ds - list only sequences \dS - list system tables and indexes \dt - list only tables \dT - list types \e [filename] - edit the current query buffer or file \E [filename] - edit the current query buffer or file and execute it upon editor exit \f [separator] - set the field separator, default=space \g [|command] [filename] - send the current query input buffer to the backend and optionally save the output in filename or pipe the output into |command. \h [command] - give syntax help \H - toggle HTML3 output \i [filename] - read queries from filename into query input buffer \l - list all databases in the server \m - toggle old monitor-like table display \o [|command] [filename] - send query results to filename or pipe into command. default=stdout \p - print the current query buffer \q - quit the psql program \r - reset/clear the query buffer \s [filename] - save commandline histor to filename \t - toggle display of output column name headings and row count (default=on) \T - set HTML3.0 options \x - toggles extended row format \w [filename] - output current query buffer to filename \z - produce a list of all tables in database with their appropriate ACLs (grant/revoke permissions) listed \! [command] - execute shell command \? - get help about the \ commands * command 'createuser' can be used to create users as the filename suggests. syntax : createuser [-dD] [-uU] [-h host] [-p port] [-i id] [username] -d : authority to create databases -D : can't create databases -u : authority to add new users -U : u guessed it!!! this command has nothing to do with the linux's own /etc/passwd file and is something totally restricted to pgsql. * command 'destroyuser -u username' can be used to do the opposite. * to create groups, edit 'pg_group' and issue the 'grant' command. * databases can be created on the commandline with 'createdb'. the person who issues this command becomes the administrator, or DBA, for this database and is the only person other than the postgres superuser who can destroy this. createdb is a shell script that uses psql and hence postmaster needs to be running on the machine. syntax : createdb [-D path] [-h host] [-p port] [-u] [dbname] -D : specifies the alternate database location -u : prompts for username and password or within psql : create database dbname; databases can be removed using 'destroydb'. syntax : destroydb [-i] [-h host] [-p port] [-u] [dbname] -i : interactive -u : prompts for username and password or withing psql: drop database dbname; * databases can be backed up using the 'pg_dump' command. > pg_dump dbname > dbname.pgdump and restored with : > cat dbname.pgdump | psql dbname > pg_dump dbname | gzip > filename.dump.gz and restored with : > createdb dbname > gunzip -c filename.dump.gz | psql dbname or : > cat filename.dump.gz | gunzip | psql dbname if u are dumping to removable media with limited storage : > pg_dump dbname | split -b 1m - filename.dump. reload with : > createdb dbname > cat filename.dump.* | pgsql dbname * there are some variables in /etc/postgresql/postmaster.init (debian) that you have to uncomment to allow the network to access pgsql over tcp/ip, they are PGALLOWTCPIP and PGPORT. hopefully these will be all that is required.