postgres usage

database creation

netbsd

    createdb -e -h 127.0.0.1 -U pgsql nobudget
    psql -U pgsql nobudget

slackware

createdb -e -h 127.0.0.1 -U postgres nobudget
    psql -U postgres nobudget

or

sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo -u postgres psql -c "CREATE DATABASE testdb;"

or yet another way

psql -U postgres

create database nobudget;

and create a user

create user nobudget with encrypted password 'PASSWORD-HERE';
grant all privileges on database nobudget to nobudget;
^D

dba ops

psql -h HOST -p PORT -U DBUSER
# -d DBNAME

list databases

\list

pick one

\c DBNAME

list tables

\dt

dba scripting

write output to file

\o out.txt
select * from TABLE;
\o
^D

as CSV

psql --csv ...

\o out.csv
select * from TABLE;
\o
^D

resources

https://stackoverflow.com/questions/12746854/postgresql-how-to-start-up-the-database-server-and-create-a-database

https://dba.stackexchange.com/questions/1285/how-do-i-list-all-databases-and-tables-using-psql

scripting

https://stackoverflow.com/questions/5331320/psql-save-results-of-command-to-a-file

https://stackoverflow.com/questions/6521531/how-do-you-print-the-result-of-a-postgresql-query-in-csv-or-tsv-format-from-the


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun