Running a Mac. I installed Postgresql 9 many years ago and configured it to auto-start. Now I have upgraded to version 12 using brew, but on system restart version 9 server is still starting automatically. I don't know how to determine what is starting it, I don't see anything in my bash_profile and I don't see a feature in brew or pg_ctl that allows me to disable an auto-start configuration. I have no postgres files in /Library/LaunchAgents either. Thanks
Postgresql – Disable auto-start of postgres server on boot (Mac)
configurationmacospostgresqlstartup
Related Solutions
Based on your situation, it would make sense I think to disable whatever PostgreSQL you have and start over with a fresh install. We are dealing with completely different applications that have nothing to do with eachother. In reality, PostgreSQL is only needed to serve up data. It makes sense to me, to simplify your life by installing PostgreSQL seperately and treating it as a totally independant application.
The simplest way to go about this, would be to take the following steps.
- Determine if PostgreSQL is currently running A. If it is, locate it and disable it B. If it isn't move onto step 2
- Download PostgreSQL 9.2 from PostgreSQL's website
- Install dependancies
- Configure, compile and install postgresql
- Initalize your database and start postgres
- What's next
1. Determine if PostgreSQL is currently running
From the shell, type the following
[root@someserver ~]# netstat -tlpn | grep postmaster
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 1119/postmaster
tcp 0 0 :::5432 :::* LISTEN 1119/postmaster
Postmaster on my machine is the PostgreSQL service. It is listening on port 5432 and has a process id of 1119.
Where is it?
Now that we have the process ID we can locate the files being used. lsof is handy because it will show you all the files and sockets a given process is using.
[root@someserver ~]# lsof -p 1119
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postmaste 1119 postgres cwd DIR 253,3 4096 131093 /var/lib/pgsql/9.1/data
postmaste 1119 postgres rtd DIR 253,0 4096 2 /
postmaste 1119 postgres txt REG 253,4 5205008 27145 /usr/pgsql-9.1/bin/postgres
On my server, it is using /usr/pgsql-9.1/bin/postgres to run the service and the /var/lib/pgsql/9.1/data is the data directory.
From this point you know where its running and what directories its using.
On your server, it looks like its installed in /usr/local/Cellar/postgresql. If you have to start it manually, then you can just leave it alone. When you install PostgreSQL from source, it will install in /usr/local/pgsql by default.
It is only important to be sure that the postgresql currently installed on your system is not using port 5432. This is because two services can not use the same port. If it is, you will need to kill the process and keep it from starting again. Based the contents of your question, it looks like that won't be a problem.
2. Download postgresql
From the shell
[root@someserver ~]# cd ~
[root@someserver ~]# wget http://ftp.postgresql.org/pub/source/v9.2.2/postgresql-9.2.2.tar.gz
[root@someserver ~]# tar -zxvf postgresql-9.2.2.tar.gz
3. Install dependencies
I didn't notice you mentionning what flavor of Linux you were running. You can identify your OS by running cat /etc/issue.
PostgreSQL depends on several libraries.
On CentOS, I would run this to install the libraries I needed
[root@someserver ~]# yum install readline-devel zlib-devel make gcc g++
On Debian, you would use apt-get to install and apt-cache search to locate. I included build-essential because you'll need it to compile postgres.
Something like apt-get install libreadline6 libreadline6-dev build-essential
Not sure about OSX though
4. Configure, Compile and Install PostgreSQL
[root@someserver ~]#
cd postgresql-9.2.2
The --bindir option will put the the postgresql binaries like pg_ctl, initdb, createdb all in the /usr/bin directory. This will be handy for you since you mentionned having trouble finding them.
./configure --bindir=/usr/bin
make
make install
You can check to see if the binaries are available
[root@someserver ~]# psql -V
psql (PostgreSQL) 9.2.2
Once this is done, normally you would need to add the postgres user, but he's already on your system You do however need to create a data directory and give postgres read/write access to it
[root@someserver ~]# mkdir -p /var/lib/pgsql/data
[root@someserver ~]# chown postgres:postgres -R /var/lib/pgsql/data
[root@someserver ~]# su - postgres
PostgreSQL is installed You have created a data directory Now you can initalize your database
5. Initalize and start postgres
initdb -D /var/lib/pgsql/data
This will the cluster and your configuration files such as postgresql.conf, pg_hba.conf which you will need to modify later based on the users that need access, their ip addresses and what ip address and port postgresql will listen on
Now you can start PostgreSQL with the following command :
/usr/local/pgsql/bin/postmaster -D /var/lib/pgsql/data > /var/lib/pgsql/logfile 2>&1 &
When you run netstat -tlpn again, you should see
[root@someserver ~]# netstat -tlpn | grep postmaster
tcp 0 0 127.0.0.1:5432 127.0.0.1:* LISTEN 8721/postmaster
It is only listening to local connections for now, because by defaut that's what postgresql.conf is configured to do.
6. What's next
From here, you would need to configure postgresql.conf and pg_hba.conf appropriately. pg_hba.conf defines who can connect, from where and to what. postgresql.conf is used to configure the entire service, what ip address or addresses it listens on, what port number, maintenance cyles, etc. For your purposes, you will probabaly only be interested in changing this variable
listen_addresses = '*'
You may also want to create an init script in the /etc/init.d directory, so it will start automatically. How you go about that also depends on what flavor of Linux you are running.
If you run into any problems let me know. Since you are probably not using the exact same system, you may run into problems I haven't discussed here.
Based on my own research, google results and ansible's answer, I was able to come up with complete solution for Oracle Linux 7. Everytime you read Kitet
- this is my Oracle Instance SID.
To start or stop database, dbstart
and dbshut
scripts are used respectively. They are located in $ORACLE_HOME/bin
. Both of them need a parameter, which is $ORACLE_HOME
. If there's no $ORACLE_HOME
environment variable, first there's a need to set it (and some more) by running
. /usr/local/bin/oraenv
(note the preceding period, and it's not $ORACLE_HOME/bin/oraenv
). Oraenv script will ask for a SID, which is needed to set correct $ORACLE_BASE. With this, using simply
dbstart $ORACLE_HOME
or
dbshut $ORACLE_HOME
will start and stop the listener and database.
To start listener using lsnrctl
or start SQL*Plus using sqlplus / as sysdba
, running . oraenv
beforehand is also required, unless user wants to set manually some environment variables. If our linux box has only one instance, there's a possibility of automating running of . oraenv
by editing user's bash profile. Enter
nano ~/.bash_profile
and type following lines (there's probably already umask 022
entry in this file, as per Oracle Database Installation Guide 12c Release 1 for Linux E41491-10
):
export ORACLE_SID=Kitet
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
export NLS_LANG=POLISH_POLAND.AL32UTF8
unicode_start
Line one and three are self explanatory. Line two will make oraenv
not ask for database SID and use exported variable. Line four is optional and will set your language preference for client connections (e.g. SQL*Plus or lsnrctl will speak in your native language, if available). Line five is needed for console to display accented characters, and is also optional.
Automating startup and shutdown of Listener and Database
1) Once the instance is created, edit the /etc/oratab
file setting the restart flag for each instance to 'Y'. My line is as follows:
Kitet:/home/oracle/app/oracle/product/12.1.0/dbhome_1:Y
2) Next, create a file called /etc/init.d/dbora
as the root user, containing the following:
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
# path to oracle home (needed only to check if dbstart exists)
ORA_HOME=/home/oracle/app/oracle/product/12.1.0/dbhome_1
# this is the user who installed oracle
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle database and listener:
# Remove "&" if you don't want startup as a background process.
export ORACLE_SID=Kitet
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
# at this point we have $ORACLE_HOME env variable set
su $ORA_OWNER -c "dbstart $ORACLE_HOME" &
touch /var/lock/subsys/dbora
;;
'stop')
# Stop the Oracle database and listener:
export ORACLE_SID=Kitet
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
su $ORA_OWNER -c "dbshut $ORACLE_HOME"
rm -f /var/lock/subsys/dbora
;;
esac
3) Use the chmod command to set the privileges to 750:
chmod 750 /etc/init.d/dbora
4) Associate the dbora service with the appropriate run levels and set it to auto-start using the following command:
chkconfig --add dbora
That's all. dbstart
and dbshut
should write to their respective logs at $ORACLE_HOME/startup.log
and $ORACLE_HOME/shutdown.log
. There also is $ORACLE_HOME/listener.log
. There we can verify if and how instance and listener started and stopped. We could also use ps -ax | grep ora
or ps -ax | grep lsnr
to see if listener / oracle are running.
Best Answer
In answer to Prevent PostgreSQL from running at startup on Super User:
ithinkiknowruby wrote: