It is necessary to create one command that will execute several commands in the terminal (bash), including the initialization of the user with a password. List and order of command execution:

  1. su postgres (a password is requested here);
  2. password entry ; - here, as I understand it, you will not get off with a simple semicolon.
  3. export PATH=$PATH:/usr/local/pgsql/bin; - this is entered from the user posgres
  4. export PGDATA=/usr/local/pgsql/data;
  5. pg_ctl start -l logfile;
  6. psql -c 'select now()';
  7. psql

Debian System Example:

Pangea @ Caesar: ~ $ startpsql;

-longs the list of all the above commands.

enter image description here

  • Use sudo, it can be prescribed in its settings that executing such a command (including the shell script) under a user like this without asking for a password. And this is the only sure way because it allows you to never write a password in clear text - Mike
  • How do i use sudo? - Aleksey
  • google: "sudo team without password" - Mike
  • What does the list of commands alias and sudo without a password? It is important for me not to write all 7 commands (specified in the question) in the terminal, it is important to find a way to optimize it all up to one word startpsql (for example) - Aleksey
  • make a text file, for example, in the / usr / local / bin folder or any other folder that is available in the paths, call it startpsql . write #!/bin/bash first line and sudo -u postgres startpsql2 second line. Create next file startpsql2 write in it with the first line #!/bin/bash after which all the lines to be executed under postgres. On both files, set permissions to execute the chmod a+x файл . Configure sudo to allow startps to the desired user without a password - Mike

0