PostgreSQL sous Linux

SyntaxeExécuter une instruction PostgreSQL depuis Linux

1
psql -c "instruction psql"
1
psql -h localhost -U user -d db -c "instruction psql"

ExempleExécuter un script PostgreSQL depuis Linux

1
#!/bin/sh
2
psql -c "DROP DATABASE mydb"
3
psql -c "CREATE DATABASE mydb"
4
psql -c "GRANT ALL PRIVILEGES ON DATABASE mydb TO user1"

Complémentpsql : exécuter une commande Linux (Linux sous Postgres)

  • \! : permet d'exécuter certaines commandes du shell Linux depuis le client psql.