cancel
Showing results for 
Search instead for 
Did you mean: 

Start postgres services with non root users wiithout sudo

Adventurer

Start postgres services with non root users wiithout sudo

please  suggest me the ideas to start and stop the postgres services with a non root user without sudo.

2 REPLIES
Level 2 Adventurer

Re: Start postgres services with non root users wiithout sudo

You can just initialize a cluster, for example,

[someuser@localhost ~]$ which initdb
/usr/pgsql-11/bin/initdb
[someuser@localhost ~]$ initdb -D ~/mydbdata
[someuser@localhost ~]$ pg_ctl -D ~/mydbdata start

This will create a database firectory in the sub-directory of your home directory.

Then you can login to the database with psql now (Note that your port might not be 5432, you need to check that).

Highlighted
EDB Team Member

Re: Start postgres services with non root users wiithout sudo

Hi varunmishra1912,

 

Just to add on alexc168's comments, if your data directory is already present, there is no need to use the initdb command. The initdb utility is used to initialize your data directory and can be done only once i.e at the beginning of a data directory's lifetime. 

 

For your service to start with non-root user you can follow :

1. Using pg_ctl utility present in bin directory, you can use following command : $PGBIN/pg_ctl -D <path_to_data_directory> start.

2. If you want to use the service file for starting the cluster, then you can do that by changing in the service files. This is something you can check with your system admin.

 

Also, the data directory should have ownership of the user by which you wishing to start the data directory and the directory permissions should be 0700.

 

Let us know in case you have any issues.