Installation
Docker
Ref: postgres in docker official repo
docker run --name some-postgres -e POSTGRES_PASSWORD=mySecretPassword -d postgres
docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'
Note do not replace "POSTGRES_PORT_5432_TCP_ADDR" with "localhost". Keep this command as is.
When prompting "Password for user postgres:", input password set in starting server, here it is "mySecretPassword".
on CentOS 6.4
Download PGDG RPM file "pgdg-centos93-9.3-1.noarch.rpm", copy to 47, install with rpm -ivh, and run:
yum list postgres*
yum install postgresql93-server_x86_64
service postgresql-9.3 initdb
chkconfig postgresql-9.3 on
service postgresql-9.3 start (restart, stop, reload)
su - postgres
Verify: $ psql list users: \du
http://wiki.postgresql.org/wiki/YUM_Installation
on XUbuntu 13.10
It said there is no saucy (ubuntu 13.10) package in postgresql repository. So I modified "saucy" to "precise":
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 pgadmin3
/etc/init.d/postgresql start
Ref: http://wiki.postgresql.org/wiki/Apt
Get Started
Run the following command with user "postgres":
$ psql
CREATE ROLE bvt LOGIN PASSWORD 'xxx';
create database mydb owner bvt;
Run psql mydb
with user bvt.
Note the semicolon after each sql statement is mandatory.
psql usage
Start psql console: psql <database_name>
.
If
Get help: \?;
List all tables: \d;
Print table contents: select * from
List roles: \du;
List databases: \l;
User "postgres" create database for a common user: create database bvt owner bvt;
Delete database: drop database
Ref: http://www.postgresql.org/docs/9.3/static/index.html