I've been working on this for about a day and I can't figure it out, I really don't know where else to look. I have a directory, /psql/data/ and I'm trying to run postgres -D /pgsql/data to start the database server. However, I get
postgres cannot access the server configuration file "/psql/data/postgresql.conf": Permission denied
Here's some background. Where I work we have an application using Flask framework that uses a Postgres database. We are running this application on an Amazon server. This application works! I know that because I've used it before. However, the person who wrote it left the company and I'm in charge of it now. And another one of my colleagues inadvertently stopped the server, so upon restart I had to set it back up.
Here's what I've tried:
postgres -D /psql/data which I read about here
From that link it also says you have to be logged in to the postgresql user account. (I just started using ubuntu about a month ago and I'm not extremely familiar with it, so forgive me if I'm making dumb statements). So I looked around and found out I could login to the postgres account with sudo su postgres. Which works! And I can see files I previously had no permissions to see. So then when I try to run postgres -D /psql/data again I get:
The program 'postgres' is currently not installed. To run 'postgres' please ask your administrator to install the package 'postgres-xc'
First I tried to install postgres-xc, but that had a missing dependency, then when I went searching I read that if I'm getting this message it's likely a greater bug, and I shouldn't have to install postgres-xc. So I stopped trying.
Ultimately, I am trying to run the application again. But before it can run it needs the database running, because without the database running when I attempt to start the flask app with python [myapp].py I get:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I've figured out that that's because the database is not running. And I can't get the database server to start. I've tried to give as much relevant information as I can, any suggestions on where I should look next will be greatly appreciated. I can also provide more information if needed.
UPDATE: The error is occurring here
engine = sqlalchemy.create_engine(conf['db'])
insp = reflection.Inspector.from_engine(engine)
the engine is created from a value in the config file, namely,
db: postgresql://work:app@localhost:5432/work
But once the second line tries to execute it errors out.
UPDATE:
VICTORY! Thank you to everyone who helped me, all of your answers combined pointed me in the right directions (but only one person can receive the bounty unfortunately).
Firstly, whenever I tried sudo -u postgres pg_ctl -D /psql/data it would error and tell me no such command. So I had to find exactly where the pg_ctl command was. It was in /usr/lib/postgres/9.3/bin/pg_ctl. So then I called sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl start -D /psql/data. This gave me an error that my configuration file had an error. Which was weird since I never touched it, but I commented that error out and then I got the real error.
The database was made using postgres 9.4 but I was using postgres 9.3.
So I had to install 9.4. Instruction can be found here. Once I did that I had to stop the previously started postgres servers with sudo service postgresql stop.
Finally I was able to start the server from the database on file with sudo -u postgres /usr/lib/postgresql/9.4/bin/pg_ctl start -D /psql/data.
Now I can access the database with sudo -su postgres then psql.
Thank you all!
in /etc/init.dthere is a file with a name postgres, pgsql or something similar.pg_hba.confin postgres data directory.