Solved

How do I start a Postgres 9 database?

Posted on 2011-03-14
21
1,181 Views
Last Modified: 2012-08-14
Experts,

       How do I start a Postgres 9 database? I looked at their site and the command is postgres -D /usr/local/pgsql/data

But  I get an error that postgres cannot be found.  How do I verify what the state is of the database? What is the syntax?

Thanks, Missymadi
0
Comment
Question by:missymadi
  • 12
  • 9
21 Comments
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
you must issue the command
sudo service postgresql start

Open in new window


to get the database running


0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
you can also use:

pg_ctl start

Open in new window


as the postgres user.

to check the status use

 pg_ctl status

Open in new window


to stop the database use:

 pg_ctl stop

Open in new window


Note, all of these are run as the postgres user.  To start or stop the database as root use:
service postgresql [start | status | stop | restart]

Open in new window


0
 

Author Comment

by:missymadi
Comment Utility
I used sudo service postgresql start and recieved " user is not in the sudoers file. This incident will be reported".

What password is it looking for?
0
 

Author Comment

by:missymadi
Comment Utility
I just read the last entry for postgres user.

I tried logging in as postgres but realized that I did not set a password for postgres....what password do I use for postgres? What is the syntax to log in as postgres? I used

su postgres

How do I give postgres a password? What is the syntax?

Thanks, Missymadi
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
log in as root and issue the "service postgresql start" command.  If you do not have access or can't log in as root, then you will need to log into the postgres user (su - postgres) and issue the "pg_ctl start" command.

issuing a sudo command is a way for super users on a computer to run commands as root, without loging is as root.  the password it is looking for the the root password, but you must be in the sudoers list to do it
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
if you didn't give postgres a password, you will have to log in as root and change the password

su - root
passwd postgres
<follow the directions>

Open in new window

0
 

Author Comment

by:missymadi
Comment Utility
I entered service postgresql start

postgresql: unrecognized service?
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
in that case try changing the postgres users password...Log in as the postgres user, and then use the pg_ctl start command
0
 

Author Comment

by:missymadi
Comment Utility
what am i doing wrong!

su postgres
pg_ctl start
bash: pg_ctl: command not found
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
as the postgres user.  Verify that your PATH variable is set to $PATH:/usr/local/pgsql/bin.  The most important part of that is the /usr/local/pgsql/bin.  Find where your binaries are installed(it should be fairly similar to that)  to set the PATH variable use this

export PATH=$PATH:/usr/local/pgsql/bin:.

Open in new window


Again.  Find the pgsql binaries, add them to your PATH variable and then issue the pg_ctl start command.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:missymadi
Comment Utility
Our setup is as follows

/usr/pgsql-9.0/bin

under bin there is clusterdb, createdb, createlang, createuser...... are these the binaries i'm looking for??
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
yes, in that folder there should be a file called pg_ctl.  I am guessing you have not initialized the database yet, so that is the first thing you need to do.  Run initdb in the /usr/pgsql-9.0/bin folder.  after this runs, pg_ctl should be in that folder.  Once it is there run pg_ctl start.
cd /usr/pgsql-9.0/bin

initdb

pg_ctl start

Open in new window

0
 

Author Comment

by:missymadi
Comment Utility
I changed directories
/usr/pgsql-9.0/bin
Tried to run initdb and get the error that initdb : command not found

What am I doing wrong? I am logged as Postgres
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
do an ls on the /usr/pgsql-9.0/bin and post the results back to the thread.
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
Also  ouput the results of echo $PATH as well.
0
 

Author Comment

by:missymadi
Comment Utility
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X1186/bin:/home/co/bin:/usr/pgsql-9.0/bin

I added the path Path=$PATH=/usr/pgsql-9.0/bin

Now I get :
you must identify the directory where the data for this dv system will reside. do this iwth either the invocation option -D or the bash-3.2$ echo $PATH

I tried usr/pgsql-9.0/bin/pg_ctl start /opt/company/CDSDB-ROOT/DATA
error: usr/pgsql-9.0/bin/pg-ctl  : No such file or directory.
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
The problem is that you must first initialize the database before you can start it.  as root to do it you can use the command:

service postgresql initdb

but that prob won't work.

in the usr/pgsql-9.0/bin/ directory try ./initdb  

If you can't see initdb in that folder you are going to have to reinstall Postgres.

And to set path it isn't Path=$PATH= ...   its Path=$PATH: ...  
0
 

Author Comment

by:missymadi
Comment Utility
Ok, I see the problem. I used a dash instead of an underscore in my path. duh

I ran
initdb -D /opt/co/CDSDB_ROOT/DATA

initdb could not create direcotry /opt/co/CDSDB_ROOT/DATA permission denied.
(running as postgres)
0
 
LVL 4

Expert Comment

by:Alex Matzinger
Comment Utility
Ok...now you just need to give prostgres permision to write to that folder.  you can either chmod the folder to allow writing from all users, or you can chown the folder and its parent folders to be owned by postgres.  Then re run the command and you should be good to go.

chmod -R 777 /opt

or 

chowm -R postgres /opt

Open in new window

0
 

Author Comment

by:missymadi
Comment Utility
I logged into PGAdmin and everything seems to be running. The db connected.

From the Konsole, how do I check the status of the Postgres db?
0
 
LVL 4

Accepted Solution

by:
Alex Matzinger earned 500 total points
Comment Utility
pg_ctl status

or 

service postgresql status

Open in new window


if these are not working, you can view the data/postmaster.pid file.  That will tell you the status of the database
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now