PostgresSQL Commands for CentOS/Linux & pg_hba.conf configuration
Login as "postgres" to start using database:
Create a new database:
Drop database:
Access database:
Get help:
Quit:
Read command from file:
To dump a database:
To reload the database:
Dump all database:
Restore database:
Show databases:
Show users:
Show tables:
Set password:
Clean all databases (Should be done via a daily cron):
Most of the time we can not install or use pgadmin. I tend to forget simple commands for administering the database. Hopefully this blog will help as reference when working with PostgreSQL
# su - postgres
$ createdb mydb
$ dropdb mydb
$ psql mydb
mydb=# \h
mydb=# \q
mydb=# \i input.sql
$ pg_dump mydb > db.out
$ psql -d database -f db.out
# su - postgres # pg_dumpall > /var/lib/pgsql/backups/dumpall.sql
# su - postgres # psql -f /var/lib/pgsql/backups/dumpall.sql mydb
#psql -l or mydb=# \l;
mydb=# SELECT * FROM "pg_user";
mydb=# SELECT * FROM "pg_tables";
mydb=# UPDATE pg_shadow SET passwd = 'new_password' where usename = 'username';
$ vacuumdb --quiet --all
The pg_hba.conf file states who is allowed to connect to the database server and which authentication method must be used to establish the connection.This configuration is very useful when we try to connect database through pgadmin client.
Default pg_hba.conf
|
# TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust |
No comments:
Post a Comment