Postgres
Version
select version();
Database Size
SELECT pg_size_pretty(pg_database_size(current_database())) as size;
Check
service postgresql status
Show current activity...
postgres=# \x auto
Expanded display is used automatically.
postgres=# SELECT * from pg_stat_activity ;
Start
As 'root'...
service postgresql start
service postgresql restart
As 'postgres'...
requires $PGDATA to be setecho $PGDATA
/var/lib/pgsql/data
pg_ctl start
Stop
As 'root'...
service postgresql stop
As 'postgres'...
requires $PGDATA to be setecho $PGDATA
/var/lib/pgsql/data
pg_ctl stop -m fast
or
pg_ctl stop -m immediate
PostgreSQL's fast option is equivalent to Oracle's immediatePostgreSQL's immediate option is equivalent to Oracle's abort !!!Local Login
su - postgres
psql
Remote Login
psql -h hostname -U username -d dbname
Initial Setup
--Locally as postgres
cd /var/lib/pgsql/data
cp postgresql.conf postgresql.conf.20190103
vi postgresql.conf
listen_addresses = '*' <---------------- by default is listen_addresses = 'localhost'
--Locally as root (restart PostgreSQL instance)
service postgresql stop
service postgresql start
--Locally as postgres
psql
postgres=# SHOW listen_addresses;
listen_addresses
------------------
*
postgres=# SHOW hba_file;
hba_file
---------------------------------
/var/lib/pgsql/data/pg_hba.conf
--Locally as postgres
cd /var/lib/pgsql/data
cp pg_hba.conf pg_hba.conf.20190103
vi pg_hba.conf <-------------- add following lines to pg_hba.conf
# 2019-01-03 Allow remote connections if the user's password is correctly supplied.
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
host all all ::/0 md5
--Locally as root (restart PostgreSQL instance)
service postgresql stop
service postgresql start
psql Shortcuts
List databases...
\l
Connect to database...
\c databasename
List tables, views and sequences...
\d
Bibliography
https://www.postgresql.org/https://www.tutorialspoint.com/postgresql/index.htmhttps://blog.bigbinary.com/2016/01/23/configure-postgresql-to-allow-remote-connection.htmlhttps://www.postgresql.org/docs/11/app-psql.htmlhttps://www.postgresql.org/docs/9.2/app-pg-ctl.htmlhttps://paquier.xyz/https://rbranson.medium.com/10-things-i-hate-about-postgresql-20dbab8c2791
Babelfish (SQL-Server/PostgreSQL interoperability)https://aws.amazon.com/blogs/opensource/want-more-postgresql-you-just-might-like-babelfish/