Search Postgresql Archives

Create schema with in a specific database from a script file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday, February 1, 2018, Abhra Kar <abhra.kar@xxxxxxxxx> wrote:

     In xyz.sh I executed the following script ---

su -c "psql -c \"\c ABC  \"" postgres

su -c "psql -c \"create schema authorization myschema\"" postgres

 

In the terminal got message “connected to ABC database”. But schema created with in postgres database not with in ABC database.


Right.  psql connected to the Postgres database, executed \c ABC which caused the session to connect to ABC.  Then, seeing no other commands, that psql session disconnected.  Then a brand new session was opened to the postgres database and in that new session created the schema.

Every psql command in a script is independent of all others, there is no state maintained.

For psql scripts in bash I find:

psql <<SQL
<script here>
SQL

To be the better form than trying to use -c.  Or put the psql code in its own file and use -f (really preferred though more files and navigation to deal with).

And you should probably try to avoid using "su" as a crutch to make things work.  Invoking commands as root is dangerous.

David J.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux