Thread: running postgresql as a linux service
Hello, I have succesfuly installed PostgreSQL 7.4.1, on my OS which is Red Hat Linux 9.0.
I start the server with:
$ pg_ctl -D /usr/local/pgsql/data -l logfile start
And stop it with:
$ pg_ctl -D /usr/local/pgsql/data stop -m fast
There are two questions here, which I want to put to you guys:
1. How can make PostgreSQL run as a Linux service so database server starts at each reboot
2. How can I register the PGDATA environment variable, so I don't have to use -D /usr/local/pgsql/data parameter (and don't use -l logfile if it is posible) when run the start command
Thanks, Raul Secan.
Raul Secan wrote: > Hello, I have succesfuly installed PostgreSQL 7.4.1, on my OS which is > Red Hat Linux 9.0. > > I start the server with: > $ pg_ctl -D /usr/local/pgsql/data -l logfile start > > And stop it with: > $ pg_ctl -D /usr/local/pgsql/data stop -m fast > > There are two questions here, which I want to put to you guys: > 1. How can make PostgreSQL run as a Linux service so database server > starts at each reboot Below are the steps I use when I manually install PostgreSQL to have it running when the server starts. However I don't use Red Hat, I use Mandrake instead. You should be able to find the corresponding files on your server if you know the installation directories for your PostgreSQL, or use utilities like 'locate' or 'find' to find out where they are installed. <start> *as root*: - Configure the PostgreSQL SysV Script. This script is useful for starting, stopping, and checking the status of PostgreSQL. # cd /usr/local/src/postgresql-7.x # cp contrib/start-scripts/linux /etc/init.d/postgres # chmod 755 /etc/init.d/postgres .... then edit the file to specify the data directory, etc. and sets the environment variabes (PGDATA etc). The file is welldocumented. If you installed Postgres manually, it should have the correct values already set. - To have PostgreSQL start automatically when the computer boots add symbolic links from the correct /etc/rc*.d/ directories to /etc/init.d/postgres. If the normal runlevel is 3 then you really only need to add it to rc3.d: # ln -s /etc/init.d/postgres /etc/rc2.d/S85postgres # ln -s /etc/init.d/postgres /etc/rc3.d/S85postgres etc ... - Start PostgreSQL for the first time: # /etc/init.d/postgres start <\start> > 2. How can I register the PGDATA environment variable, so I don't have > to use -D /usr/local/pgsql/data parameter (and don't use -l logfile if > it is posible) when run the start command > If step 1. works correctly, the PGDATA variable is set properly. Otherwise edit the /etc/init.d/postgres file. > Thanks, Raul Secan. Ron
On Thu, Mar 18, 2004 at 05:22:07PM +0200, Raul Secan wrote: > Hello, I have succesfuly installed PostgreSQL 7.4.1, on my OS which is Red Hat Linux 9.0. > > I start the server with: > $ pg_ctl -D /usr/local/pgsql/data -l logfile start > > And stop it with: > $ pg_ctl -D /usr/local/pgsql/data stop -m fast > > There are two questions here, which I want to put to you guys: > 1. How can make PostgreSQL run as a Linux service so database server > starts at each reboot run 'ntsysv' as root, and make sure the checkbox next to "postgresql" is turned on. > 2. How can I register the PGDATA environment variable, so I don't have to > use -D /usr/local/pgsql/data parameter (and don't use -l logfile if it is > posible) when run the start command > I generally use something like: # /usr/sbin/service postgresql start to start the service, and "stop" to stop it. this *should* take care of dealing with the -D option. > Thanks, Raul Secan. hope that helps. regards, J
Attachment
I saw that in /etc/init.d/ dir I already have postgresql, so the service is installed, bu wehn try to run: service postgresql start I receive: Initializing database: [FAILED] Starting postgresql service: pg_ctl: no operation mode specified Try "pg_ctl --help" for more information. -sh: line 2: -p: command not found Anyway I just edit the postgresql file and see something anormal there I think: export PGDATA=/var/lib/pgsql/data But my Postgresql data dir is /usr/local/pgsql/data. Can someone tell me what is going on? Thanks. ----- Original Message ----- From: "Ron St-Pierre" <rstpierre@syscor.com> To: "Raul Secan" <raul@zerosoft.ro>; <pgsql-php@postgresql.org> Sent: Thursday, March 18, 2004 5:57 PM Subject: Re: [PHP] running postgresql as a linux service Raul Secan wrote: > Hello, I have succesfuly installed PostgreSQL 7.4.1, on my OS which is > Red Hat Linux 9.0. > > I start the server with: > $ pg_ctl -D /usr/local/pgsql/data -l logfile start > > And stop it with: > $ pg_ctl -D /usr/local/pgsql/data stop -m fast > > There are two questions here, which I want to put to you guys: > 1. How can make PostgreSQL run as a Linux service so database server > starts at each reboot Below are the steps I use when I manually install PostgreSQL to have it running when the server starts. However I don't use Red Hat, I use Mandrake instead. You should be able to find the corresponding files on your server if you know the installation directories for your PostgreSQL, or use utilities like 'locate' or 'find' to find out where they are installed. <start> *as root*: - Configure the PostgreSQL SysV Script. This script is useful for starting, stopping, and checking the status of PostgreSQL. # cd /usr/local/src/postgresql-7.x # cp contrib/start-scripts/linux /etc/init.d/postgres # chmod 755 /etc/init.d/postgres .... then edit the file to specify the data directory, etc. and sets the environment variabes (PGDATA etc). The file is well documented. If you installed Postgres manually, it should have the correct values already set. - To have PostgreSQL start automatically when the computer boots add symbolic links from the correct /etc/rc*.d/ directories to /etc/init.d/postgres. If the normal runlevel is 3 then you really only need to add it to rc3.d: # ln -s /etc/init.d/postgres /etc/rc2.d/S85postgres # ln -s /etc/init.d/postgres /etc/rc3.d/S85postgres etc ... - Start PostgreSQL for the first time: # /etc/init.d/postgres start <\start> > 2. How can I register the PGDATA environment variable, so I don't have > to use -D /usr/local/pgsql/data parameter (and don't use -l logfile if > it is posible) when run the start command > If step 1. works correctly, the PGDATA variable is set properly. Otherwise edit the /etc/init.d/postgres file. > Thanks, Raul Secan. Ron ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster
On Fri, 19 Mar 2004 11:49:36 +0200 "Raul Secan" <raul@zerosoft.ro> sat down, thought long and then wrote: > I saw that in /etc/init.d/ dir I already have postgresql, so the service is > installed, bu wehn try to run: > > service postgresql start > > I receive: > > Initializing database: [FAILED] > Starting postgresql service: pg_ctl: no operation mode specified > Try "pg_ctl --help" for more information. > -sh: line 2: -p: command not found > > Anyway I just edit the postgresql file and see something anormal there I > think: > > export PGDATA=/var/lib/pgsql/data > > But my Postgresql data dir is /usr/local/pgsql/data. > > Can someone tell me what is going on? > Thanks. > On SuSE distributions for example, if you use (or ever installed) the shipped PostgreSQL release, you find a startstop-script, which also does not work with a self compiled release (and also uses /var/lib/pgsql/data as PGDATA). If it´s the same with your distribution, simply delete this script. I recommend the start-script you find in "/contrib/start-scripts/linux" in the PostgreSQL tarball. Copy it to /etc/init.d and follow the further instructions inside this script. Don´t forget to chmod it executable. For me it works very well on several servers. Regards, Frank.
I haven't had access to my mail over the last few days, so in case you are still having a problem, check below. Raul Secan wrote: >I saw that in /etc/init.d/ dir I already have postgresql, so the service is >installed, bu wehn try to run: > >service postgresql start > >I receive: > >Initializing database: [FAILED] >Starting postgresql service: pg_ctl: no operation mode specified >Try "pg_ctl --help" for more information. >-sh: line 2: -p: command not found > >Anyway I just edit the postgresql file and see something anormal there I >think: > >export PGDATA=/var/lib/pgsql/data > >But my Postgresql data dir is /usr/local/pgsql/data. > >Can someone tell me what is going on? >Thanks. > > This is why you have to copy over the 'postgres' file in /etc/init.d cp contrib/start-scripts/linux /etc/init.d/postgres If you have properly installed postgres then the file that you are copying over from contrib/start-scripts/ will be properly configured with the correct environment variables. I would also recommend that you delete anything in your /var/lib/pgsql/ directory if you haven't already done so (after backing up any databases you may have). >----- Original Message ----- >From: "Ron St-Pierre" <rstpierre@syscor.com> >To: "Raul Secan" <raul@zerosoft.ro>; <pgsql-php@postgresql.org> >Sent: Thursday, March 18, 2004 5:57 PM >Subject: Re: [PHP] running postgresql as a linux service > > >Raul Secan wrote: > > > >>Hello, I have succesfuly installed PostgreSQL 7.4.1, on my OS which is >>Red Hat Linux 9.0. >> >>I start the server with: >>$ pg_ctl -D /usr/local/pgsql/data -l logfile start >> >>And stop it with: >>$ pg_ctl -D /usr/local/pgsql/data stop -m fast >> >>There are two questions here, which I want to put to you guys: >>1. How can make PostgreSQL run as a Linux service so database server >>starts at each reboot >> >> > >Below are the steps I use when I manually install PostgreSQL to have it >running when the server starts. However I don't use Red Hat, I use >Mandrake instead. You should be able to find the corresponding files on >your server if you know the installation directories for your >PostgreSQL, or use utilities like 'locate' or 'find' to find out where >they are installed. > ><start> > >*as root*: >- Configure the PostgreSQL SysV Script. This script is useful for >starting, stopping, and checking the status of PostgreSQL. > ># cd /usr/local/src/postgresql-7.x ># cp contrib/start-scripts/linux /etc/init.d/postgres ># chmod 755 /etc/init.d/postgres >.... then edit the file to specify the data directory, etc. and sets the >environment variabes (PGDATA etc). The file is well documented. If you >installed Postgres manually, it should have the correct values already set. > >- To have PostgreSQL start automatically when the computer boots add >symbolic links from the correct /etc/rc*.d/ directories to >/etc/init.d/postgres. If the normal runlevel is 3 then you really only >need to add it to rc3.d: > ># ln -s /etc/init.d/postgres /etc/rc2.d/S85postgres ># ln -s /etc/init.d/postgres /etc/rc3.d/S85postgres > >etc ... > >- Start PostgreSQL for the first time: > ># /etc/init.d/postgres start > ><\start> > > > >>2. How can I register the PGDATA environment variable, so I don't have >>to use -D /usr/local/pgsql/data parameter (and don't use -l logfile if >>it is posible) when run the start command >> >> >> > >If step 1. works correctly, the PGDATA variable is set properly. >Otherwise edit the /etc/init.d/postgres file. > > > >>Thanks, Raul Secan. >> >> > > >Ron > > > > >---------------------------(end of broadcast)--------------------------- >TIP 4: Don't 'kill -9' the postmaster > > > >
When you install postgres from the rpm or the tar or zipped tar files, you run configure, make and make install. When these are run they update certain configuration files, including the file /contrib/start-scripts/linux If you look in your current /etc/init.d/postgres file you will probably see the line: PGDATA=/var/lib/pgsql/data If you look in the file contrib/start-scripts/linux you will see that PGDATA is set correctly as: PGDATA="/usr/local/pgsql/data" That is why you have to replace/overwrite the postgres file with the linux file, using the copy command: cp contrib/start-scripts/linux /etc/init.d/postgres Even before you do that you can try to start postgres as user postgres: pg_ctl start -D /usr/local/pgsql/data The pg_ctl executable is in the /usr/local/pgsql/bin directory, but if postgres is properly installed this should be in yourpath. The -D argument tells postgres where your data directory is. Use pg_ctl --help for more information. Ron Raul Secan wrote: >Thanks for the TIP with the start-script, but I am still wondering why I >can't start the service with: > >service postgresql start > >Because everyting seems to be installed correctly. > >Thanks. > >----- Original Message ----- >From: "Ron St-Pierre" <rstpierre@syscor.com> >To: "Raul Secan" <raul@zerosoft.ro>; <pgsql-php@postgresql.org> >Sent: Monday, March 22, 2004 6:35 PM >Subject: Re: [PHP] running postgresql as a linux service > > >I haven't had access to my mail over the last few days, so in case you >are still having a problem, check below. > >Raul Secan wrote: > > > >>I saw that in /etc/init.d/ dir I already have postgresql, so the service is >>installed, bu wehn try to run: >> >>service postgresql start >> >>I receive: >> >>Initializing database: [FAILED] >>Starting postgresql service: pg_ctl: no operation mode specified >>Try "pg_ctl --help" for more information. >>-sh: line 2: -p: command not found >> >>Anyway I just edit the postgresql file and see something anormal there I >>think: >> >>export PGDATA=/var/lib/pgsql/data >> >>But my Postgresql data dir is /usr/local/pgsql/data. >> >>Can someone tell me what is going on? >>Thanks. >> >> >> >> >This is why you have to copy over the 'postgres' file in /etc/init.d > cp contrib/start-scripts/linux /etc/init.d/postgres >If you have properly installed postgres then the file that you are >copying over from contrib/start-scripts/ will be properly configured >with the correct environment variables. I would also recommend that you >delete anything in your /var/lib/pgsql/ directory if you haven't already >done so (after backing up any databases you may have). > > > >>----- Original Message ----- >>From: "Ron St-Pierre" <rstpierre@syscor.com> >>To: "Raul Secan" <raul@zerosoft.ro>; <pgsql-php@postgresql.org> >>Sent: Thursday, March 18, 2004 5:57 PM >>Subject: Re: [PHP] running postgresql as a linux service >> >> >>Raul Secan wrote: >> >> >> >> >> >>>Hello, I have succesfuly installed PostgreSQL 7.4.1, on my OS which is >>>Red Hat Linux 9.0. >>> >>>I start the server with: >>>$ pg_ctl -D /usr/local/pgsql/data -l logfile start >>> >>>And stop it with: >>>$ pg_ctl -D /usr/local/pgsql/data stop -m fast >>> >>>There are two questions here, which I want to put to you guys: >>>1. How can make PostgreSQL run as a Linux service so database server >>>starts at each reboot >>> >>> >>> >>> >>Below are the steps I use when I manually install PostgreSQL to have it >>running when the server starts. However I don't use Red Hat, I use >>Mandrake instead. You should be able to find the corresponding files on >>your server if you know the installation directories for your >>PostgreSQL, or use utilities like 'locate' or 'find' to find out where >>they are installed. >> >><start> >> >>*as root*: >>- Configure the PostgreSQL SysV Script. This script is useful for >>starting, stopping, and checking the status of PostgreSQL. >> >># cd /usr/local/src/postgresql-7.x >># cp contrib/start-scripts/linux /etc/init.d/postgres >># chmod 755 /etc/init.d/postgres >>.... then edit the file to specify the data directory, etc. and sets the >>environment variabes (PGDATA etc). The file is well documented. If you >>installed Postgres manually, it should have the correct values already set. >> >>- To have PostgreSQL start automatically when the computer boots add >>symbolic links from the correct /etc/rc*.d/ directories to >>/etc/init.d/postgres. If the normal runlevel is 3 then you really only >>need to add it to rc3.d: >> >># ln -s /etc/init.d/postgres /etc/rc2.d/S85postgres >># ln -s /etc/init.d/postgres /etc/rc3.d/S85postgres >> >>etc ... >> >>- Start PostgreSQL for the first time: >> >># /etc/init.d/postgres start >> >><\start> >> >> >> >> >> >>>2. How can I register the PGDATA environment variable, so I don't have >>>to use -D /usr/local/pgsql/data parameter (and don't use -l logfile if >>>it is posible) when run the start command >>> >>> >>> >>> >>> >>If step 1. works correctly, the PGDATA variable is set properly. >>Otherwise edit the /etc/init.d/postgres file. >> >> >> >> >> >>>Thanks, Raul Secan. >>> >>> >>> >>> >>Ron >> >> >> >> >>---------------------------(end of broadcast)--------------------------- >>TIP 4: Don't 'kill -9' the postmaster >> >> >> >> >> >> > > > >