mirror of
https://github.com/Erreur32/cheat.git
synced 2025-01-03 11:32:17 +01:00
added psql commands
This commit is contained in:
parent
edd7b5e806
commit
2a6ec9cef5
1 changed files with 21 additions and 0 deletions
21
cheat/cheatsheets/psql
Normal file
21
cheat/cheatsheets/psql
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#psql is the PostgreSQL terminal interface. The following commands were tested on version 9.5.
|
||||||
|
#Connection options:
|
||||||
|
#-U username (if not specified current OS user is used).
|
||||||
|
#-p port.
|
||||||
|
#-h server hostname/address.
|
||||||
|
|
||||||
|
#Connect to a specific database:
|
||||||
|
psql -U postgres -h serverAddress -d dbName
|
||||||
|
|
||||||
|
#Get databases on a server:
|
||||||
|
psql -U postgres -h serverAddress --list
|
||||||
|
|
||||||
|
#Execute sql query and save output to file:
|
||||||
|
#Add -t to get only rows as result.
|
||||||
|
psql -U postgres -d dbName -c 'select * from tableName;' -o 'fileName'
|
||||||
|
|
||||||
|
Read commands from file:
|
||||||
|
psql -f fileName
|
||||||
|
|
||||||
|
#Restore databases from file:
|
||||||
|
psql -f /fileName.backup postgres
|
Loading…
Reference in a new issue