Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1331
  • Last Modified:

How do I start a Postgres 9 database?

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
missymadi
Asked:
missymadi
  • 12
  • 9
1 Solution
 
Alex MatzingerDatabase AdministratorCommented:
you must issue the command
sudo service postgresql start

Open in new window


to get the database running


0
 
Alex MatzingerDatabase AdministratorCommented:
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
 
missymadiAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
missymadiAuthor Commented:
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
 
Alex MatzingerDatabase AdministratorCommented:
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
 
Alex MatzingerDatabase AdministratorCommented:
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
 
missymadiAuthor Commented:
I entered service postgresql start

postgresql: unrecognized service?
0
 
Alex MatzingerDatabase AdministratorCommented:
in that case try changing the postgres users password...Log in as the postgres user, and then use the pg_ctl start command
0
 
missymadiAuthor Commented:
what am i doing wrong!

su postgres
pg_ctl start
bash: pg_ctl: command not found
0
 
Alex MatzingerDatabase AdministratorCommented:
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
 
missymadiAuthor Commented:
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
 
Alex MatzingerDatabase AdministratorCommented:
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
 
missymadiAuthor Commented:
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
 
Alex MatzingerDatabase AdministratorCommented:
do an ls on the /usr/pgsql-9.0/bin and post the results back to the thread.
0
 
Alex MatzingerDatabase AdministratorCommented:
Also  ouput the results of echo $PATH as well.
0
 
missymadiAuthor Commented:
/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
 
Alex MatzingerDatabase AdministratorCommented:
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
 
missymadiAuthor Commented:
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
 
Alex MatzingerDatabase AdministratorCommented:
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
 
missymadiAuthor Commented:
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
 
Alex MatzingerDatabase AdministratorCommented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 12
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now