I want to install a postgresql database on a remote linux server. In order to create the database on the remote server, I wrote a script in a python that executes the commands on the server. I am running the commands in sequential order in like this:
cmd = "wget http://yum.pgrpms.org/reporpms/8.4/pgdg-centos-8.4-2.noarch.rpm" execute cmd cmd = "rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-centos-8.4-2.noarch.rpm" execute cmd cmd = "yum install postgresql postgresql-server" execute cmd
...and so on.
Everthing works fine utill the installation of postgres and starting the database. The problem arises when I want to create a database in postgreql. I found that I have to switch to the 'postgres' user and run
psql in order to execute any database related commands. For example:
# su postgres # psql # create database test;
...but since I am passing all of the commnads sequentially through the remote python code (as shown in the first example), it seems quite impossible to run these three commands together (
su postgres, and
create) from the client. Is there any way to run all three commands together?
I run following command:
# su postgres && psql && create database test;
...but only the first comamnd (
su postgres) is executed.