Where does PostgreSQL store the database? - postgresql

Where are the files for a PostgreSQL database stored?

To see where the data directory is, use this query.
show data_directory;
To see all the run-time parameters, use
show all;
You can create tablespaces to store database objects in other parts of the filesystem. To see tablespaces, which might not be in that data directory, use this query.
SELECT *, pg_tablespace_location(oid) FROM pg_tablespace;

On Windows7 all the databases are referred by a number in the file named pg_database under C:\Program Files (x86)\PostgreSQL\8.2\data\global. Then you should search for the folder name by that number under C:\Program Files (x86)\PostgreSQL\8.2\data\base. That is the content of the database.

As suggested in "PostgreSQL database default location on Linux", under Linux you can find out using the following command:
ps aux | grep postgres | grep -- -D

Open pgAdmin and go to Properties for specific database. Find OID and then open directory
<POSTGRESQL_DIRECTORY>/data/base/<OID>
There should be your DB files.

Under my Linux installation, it's here: /var/lib/postgresql/8.x/
You can change it with initdb -D "c:/mydb/"

Everyone already answered but just for the latest updates. If you want to know where all the configuration files reside then run this command in the shell
SELECT name, setting FROM pg_settings WHERE category = 'File Locations';

I'd bet you're asking this question because you've tried pg_ctl start and received the following error:
pg_ctl: no database directory specified and environment variable PGDATA unset
In other words, you're looking for the directory to put after -D in your pg_ctl start command.
In this case, the directory you're looking for contains these files.
PG_VERSION pg_dynshmem pg_multixact
pg_snapshots pg_tblspc postgresql.conf
base pg_hba.conf pg_notify
pg_stat pg_twophase postmaster.opts
global pg_ident.conf pg_replslot
pg_stat_tmp pg_xlog postmaster.pid
pg_clog pg_logical pg_serial
pg_subtrans postgresql.auto.conf server.log
You can locate it by locating any of the files and directories above using the search provided with your OS.
For example in my case (a HomeBrew install on Mac OS X), these files are located in /usr/local/var/postgres. To start the server I type:
pg_ctl -D /usr/local/var/postgres -w start
... and it works.

Postgres stores data in files in its data directory. Follow the steps below to go to a database and its files:
The database corresponding to a postgresql table file is a directory. The location of the entire data directory can be obtained by running SHOW data_directory.
in a UNIX like OS (eg: Mac) /Library/PostgreSQL/9.4/data
Go inside the base folder in the data directory which has all the database folders: /Library/PostgreSQL/9.4/data/base
Find the database folder name by running (Gives an integer. This is the database folder name):
SELECT oid from pg_database WHERE datname = <database_name>;
Find the table file name by running (Gives an integer. This is the file name):
SELECT relname, relfilenode FROM pg_class WHERE relname = <table_name>;
This is a binary file. File details such as size and creation date time can be obtained as usual. For more info read this SO thread

The location of specific tables/indexes can be adjusted by TABLESPACEs:
CREATE TABLESPACE dbspace LOCATION '/data/dbs';
CREATE TABLE something (......) TABLESPACE dbspace;
CREATE TABLE otherthing (......) TABLESPACE dbspace;

On Mac: /Library/PostgreSQL/9.0/data/base
The directory can't be entered, but you can look at the content via: sudo du -hc data

picmate's answer is right. on windows the main DB folder location is (at least on my installation)
C:\PostgreSQL\9.2\data\base\
and not in program files.
his 2 scripts, will give you the exact directory/file(s) you need:
SELECT oid from pg_database WHERE datname = <database_name>;
SELECT relname, relfilenode FROM pg_class WHERE relname = <table_name>;
mine is in datname 16393 and relfilenode 41603

On Windows, the PGDATA directory that the PostgresSQL docs describe is at somewhere like C:\Program Files\PostgreSQL\8.1\data. The data for a particular database is under (for example) C:\Program Files\PostgreSQL\8.1\data\base\100929, where I guess 100929 is the database number.

I'm running postgres (9.5) in a docker container (on CentOS, as it happens), and as Skippy le Grand Gourou mentions in a comment above, the files are located in /var/lib/postgresql/data/.
$ docker exec -it my-postgres-db-container bash
root#c7d61efe2a5d:/# cd /var/lib/postgresql/data/
root#c7d61efe2a5d:/var/lib/postgresql/data# ls -lh
total 56K
drwx------. 7 postgres postgres 71 Apr 5 2018 base
drwx------. 2 postgres postgres 4.0K Nov 2 02:42 global
drwx------. 2 postgres postgres 18 Dec 27 2017 pg_clog
drwx------. 2 postgres postgres 6 Dec 27 2017 pg_commit_ts
drwx------. 2 postgres postgres 6 Dec 27 2017 pg_dynshmem
-rw-------. 1 postgres postgres 4.4K Dec 27 2017 pg_hba.conf
-rw-------. 1 postgres postgres 1.6K Dec 27 2017 pg_ident.conf
drwx------. 4 postgres postgres 39 Dec 27 2017 pg_logical
drwx------. 4 postgres postgres 36 Dec 27 2017 pg_multixact
drwx------. 2 postgres postgres 18 Nov 2 02:42 pg_notify
drwx------. 2 postgres postgres 6 Dec 27 2017 pg_replslot
drwx------. 2 postgres postgres 6 Dec 27 2017 pg_serial
drwx------. 2 postgres postgres 6 Dec 27 2017 pg_snapshots
drwx------. 2 postgres postgres 6 Sep 16 21:15 pg_stat
drwx------. 2 postgres postgres 63 Nov 8 02:41 pg_stat_tmp
drwx------. 2 postgres postgres 18 Oct 24 2018 pg_subtrans
drwx------. 2 postgres postgres 6 Dec 27 2017 pg_tblspc
drwx------. 2 postgres postgres 6 Dec 27 2017 pg_twophase
-rw-------. 1 postgres postgres 4 Dec 27 2017 PG_VERSION
drwx------. 3 postgres postgres 92 Dec 20 2018 pg_xlog
-rw-------. 1 postgres postgres 88 Dec 27 2017 postgresql.auto.conf
-rw-------. 1 postgres postgres 21K Dec 27 2017 postgresql.conf
-rw-------. 1 postgres postgres 37 Nov 2 02:42 postmaster.opts
-rw-------. 1 postgres postgres 85 Nov 2 02:42 postmaster.pid

A single Terminal command: pg_lsclusters, (using Ubuntu)
What you need is under Data directory:
Ver Cluster Port Status Owner Data directory Log file
10 main 5432 online postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
11 main 5433 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log

Related

Neither initb -D nor a changed data_direectoy is recognized by postgresql service

I want to change the data_directory of my postgresql database cluster. I found 2 ways to do this, non of them work for me.
From documentation what I do is:
yum install postgresql-server
create new linux user "postgres"
sudo mkdir /home2
sudo mkdir /home2/data
sudo chown postgres:postgres /home2
sudo chown postgres:postgres /home2/data
Now the trouble begins in both cases:
Variant 1:
✘ root#localhost /var/lib/pgsql/data # postgresql-setup initdb
Initializing database ... OK
✘ root#localhost /var/lib/pgsql/data # l
total 44K
drwx------. 15 postgres postgres 4.0K May 17 08:02 .
drwx------. 4 postgres postgres 72 May 16 15:17 ..
drwx------. 5 postgres postgres 41 May 17 08:02 base
drwx------. 2 postgres postgres 4.0K May 17 08:02 global
drwx------. 2 postgres postgres 18 May 17 08:02 pg_clog
-rw-------. 1 postgres postgres 4.2K May 17 08:02 pg_hba.conf
-rw-------. 1 postgres postgres 1.6K May 17 08:02 pg_ident.conf
drwx------. 2 postgres postgres 6 May 17 08:02 pg_log
drwx------. 4 postgres postgres 36 May 17 08:02 pg_multixact
drwx------. 2 postgres postgres 18 May 17 08:02 pg_notify
drwx------. 2 postgres postgres 6 May 17 08:02 pg_serial
drwx------. 2 postgres postgres 6 May 17 08:02 pg_snapshots
drwx------. 2 postgres postgres 6 May 17 08:02 pg_stat_tmp
drwx------. 2 postgres postgres 18 May 17 08:02 pg_subtrans
drwx------. 2 postgres postgres 6 May 17 08:02 pg_tblspc
drwx------. 2 postgres postgres 6 May 17 08:02 pg_twophase
-rw-------. 1 postgres postgres 4 May 17 08:02 PG_VERSION
drwx------. 3 postgres postgres 60 May 17 08:02 pg_xlog
-rw-------. 1 postgres postgres 20K May 17 08:02 postgresql.conf
root#localhost /var/lib/pgsql/data #
Starting a terminal as postgres-user:
-bash-4.2$ psql
psql (9.2.24)
Type "help" for help.
postgres=# SHOW data_directory;
data_directory
---------------------
/var/lib/pgsql/data
(1 row)
postgres=#
I did systemctl stop psotgresql, edited the postgresql.conf and changed data_directory = '/home2/data'. When I do systemctl start psotgresql I get
FATAL: "/home2/data" is not a valid data directory
DETAIL: File "/home2/data/PG_VERSION" is missing.
so I did
-bash-4.2$ initdb -D /home2/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
fixing permissions on existing directory /home2/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /home2/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
postgres -D /home2/data
or
pg_ctl -D /home2/data -l logfile start
-bash-4.2$
as postgres user. When I try to start the postgresql server again using systemctl start postgresql the terminal won't finish
root#localhost /var/lib/pgsql/data # systemctl start postgresql
but the server is running, I can login as postgres user
-bash-4.2$ psql
psql (9.2.24)
Type "help" for help.
postgres=# SHOW data_directory;
data_directory
----------------
/home2/data
(1 row)
postgres=#
What is going wrong here? Why doesn't the service "prompt" finish? After quite some time the service is getting a timeout and coming back. The database doesn't run anymore then.
Job for postgresql.service failed because a timeout was exceeded. See "systemctl status postgresql.service" and "journalctl -xe" for details.
✘ root#localhost /var/lib/pgsql/data #
Variant 2:
New fresh local VM did the steps from the top until the trouble begins:
-bash-4.2$ initdb -D /home2/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
fixing permissions on existing directory /home2/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /home2/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
postgres -D /home2/data
or
pg_ctl -D /home2/data -l logfile start
-bash-4.2$ ls -l /home2/data/
total 40
drwx------. 5 postgres postgres 41 May 17 08:20 base
drwx------. 2 postgres postgres 4096 May 17 08:20 global
drwx------. 2 postgres postgres 18 May 17 08:20 pg_clog
-rw-------. 1 postgres postgres 4476 May 17 08:20 pg_hba.conf
-rw-------. 1 postgres postgres 1636 May 17 08:20 pg_ident.conf
drwx------. 4 postgres postgres 36 May 17 08:20 pg_multixact
drwx------. 2 postgres postgres 18 May 17 08:20 pg_notify
drwx------. 2 postgres postgres 6 May 17 08:20 pg_serial
drwx------. 2 postgres postgres 6 May 17 08:20 pg_snapshots
drwx------. 2 postgres postgres 6 May 17 08:20 pg_stat_tmp
drwx------. 2 postgres postgres 18 May 17 08:20 pg_subtrans
drwx------. 2 postgres postgres 6 May 17 08:20 pg_tblspc
drwx------. 2 postgres postgres 6 May 17 08:20 pg_twophase
-rw-------. 1 postgres postgres 4 May 17 08:20 PG_VERSION
drwx------. 3 postgres postgres 60 May 17 08:20 pg_xlog
-rw-------. 1 postgres postgres 19865 May 17 08:20 postgresql.conf
-bash-4.2$
When trying to start the postgresql service
✘ root#localhost /var/lib/pgsql/data # systemctl restart postgresql
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.
✘ root#localhost /var/lib/pgsql/data # journalctl -xe
...
May 17 08:20:58 localhost.localdomain postgresql-check-db-dir[15283]: "/var/lib/pgsql/data" is missing or empty.
May 17 08:20:58 localhost.localdomain postgresql-check-db-dir[15283]: Use "postgresql-setup initdb" to initialize the database cluster.
May 17 08:20:58 localhost.localdomain postgresql-check-db-dir[15283]: See /usr/share/doc/postgresql-9.2.24/README.rpm-dist for more information.
May 17 08:20:58 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
May 17 08:20:58 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
...
so the postgresql-service doesn't see I already did initdb. When I do postgresql-setup initdb it simply creates the data directory unter the default location. Running the postgresql as postgres user postgres -D /home2/data does work, but I had to create some kind of service out of this command so I won't have to keep my terminal opened.
Environment: CentOS 7
I'm doing a first test-installation in a local vagrant box. While doing this I write code in ansible. So usually I'm not using the root user ;)
Probably the solution for my issues
After doing some research I found a guide which brought me a little further to my solution. After taking a look into my cat /usr/lib/systemd/system/postgresql.service There was a part saying
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql.service",
# containing
# .include /lib/systemd/system/postgresql.service
# ...make your changes here...
so I did this:
# vi /etc/systemd/system/postgresql.service
.include /lib/systemd/system/postgresql.service
[Service]
Environment=PGDATA=/home2/data
and finally I can just simply do postgresql-setup initdb and my database-cluster is getting installed into the correct directory and I can use my system-services just like it's meant to be.
I will mark this as solution as soon as I can confirm the database is running fine without having any trouble.

PostgreSQL keeps WAL segments not required by any replication slot

I have wal_keep_segments set to 3000. But directory pg_xlog contains more than 6000 WAL segments. Interesting thing that there are ~ 3000 files dated after Aug 14, so files dated before Aug 14 should not be exists, I guess. Also these files have an executable bit set.
$ ls -al pg_xlog | grep -A2 -B2 00000001000034DB0000003B
-rwx------ 1 postgres postgres 16777216 Jul 19 07:58 00000001000034DB00000039
-rwx------ 1 postgres postgres 16777216 Jul 19 07:58 00000001000034DB0000003A
-rwx------ 1 postgres postgres 16777216 Jul 19 07:58 00000001000034DB0000003B
-rw------- 1 postgres postgres 16777216 Aug 14 19:17 0000000100003826000000EA
-rw------- 1 postgres postgres 16777216 Aug 14 19:17 0000000100003826000000EB
```
This cluster has no replication slots, archive_mode is enabled but archive_command is set to /bin/true. I think the new WAL segments are recycled and total amount is about 6000 but postgres does not delete the old files for some reason. Any ideas?
PostgreSQL is not in the habit of setting executable flags on WAL segments.
Besides, it looks like there is a gap in the numbering.
These files must be there by accident, you can delete them.

Postgres restore from WAL files without having a basebackup using pg_basebackup

I have the following situation.
Have a master/replica setup.
Somehow the database was dropped and a new database with the same name was created by django. in this case, will the WAL files of the previous database still be there?
I have not created a backup using of the previous database using a tool like pg_basebackup, but do have some WAL files in the pg_xlog.
Now, i am trying to do the following:
- Shutdown the postgres server.
- Use the recovery.conf file in PGDATA (/var/lib/postgresql/9.3/main) directory and entering the following in there:
restore_command = 'cp /var/lib/postgresql/9.3/main/pg_xlog_backup_jan072016/%f %p'
recovery_target_time = '2016-01-07 03:00:00'
- Startup the postgres server again.
What I see in the log file is:
postgres:~/9.3/main/pg_log$ tail -100f postgresql-2016-01-07_170256.log
2016-01-07 17:02:56 UTC LOG: database system was shut down at 2016-01-07 17:02:55 UTC
2016-01-07 17:02:56 UTC LOG: starting point-in-time recovery to 2016-01-06 00:00:00+00
cp: cannot stat ‘/var/lib/postgresql/9.3/main/pg_xlog_backup_jan072016/0000000A.history’: No such file or directory
cp: cannot stat ‘/var/lib/postgresql/9.3/main/pg_xlog_backup_jan072016/0000000A00000000000000CC’: No such file or directory
2016-01-07 17:02:56 UTC LOG: consistent recovery state reached at 0/CC000090
2016-01-07 17:02:56 UTC LOG: record with zero length at 0/CC000090
2016-01-07 17:02:56 UTC LOG: redo is not required
2016-01-07 17:02:56 UTC LOG: database system is ready to accept read only connections
cp: cannot stat ‘/var/lib/postgresql/9.3/main/pg_xlog_backup_jan072016/0000000A00000000000000CC’: No such file or directory
cp: cannot stat ‘/var/lib/postgresql/9.3/main/pg_xlog_backup_jan072016/0000000B.history’: No such file or directory
2016-01-07 17:02:56 UTC LOG: selected new timeline ID: 11
cp: cannot stat ‘/var/lib/postgresql/9.3/main/pg_xlog_backup_jan072016/0000000A.history’: No such file or directory
2016-01-07 17:02:57 UTC LOG: archive recovery complete
2016-01-07 17:02:57 UTC LOG: autovacuum launcher started
2016-01-07 17:02:57 UTC LOG: database system is ready to accept connections
2016-01-07 17:02:57 UTC LOG: incomplete startup packet
My pg_xlog_backup_jan072016 folder has the foll content.:
:~/9.3/main/pg_xlog_backup_jan072016$ ls -larth
total 161M
-rw------- 1 postgres postgres 257 Jan 7 15:57 00000007.history
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000CA
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C9
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C8
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C7
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C6
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C5
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C4
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C3
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C2
-rw------- 1 postgres postgres 16M Jan 7 15:57 0000000700000000000000C1
-rw------- 1 postgres postgres 298 Jan 7 15:57 00000007000000000000005D.00000028.backup
-rw------- 1 postgres postgres 214 Jan 7 15:57 00000006.history
-rw------- 1 postgres postgres 171 Jan 7 15:57 00000005.history
drwx------ 3 postgres postgres 4.0K Jan 7 16:54 .
drwx------ 18 postgres postgres 4.0K Jan 7 17:02 ..
drwx------ 2 postgres postgres 4.0K Jan 7 17:08 archive_status
The thing I am trying to figure out is:
Is it possible to restore from WAL without have a backup from pg_basebackup command? I am just trying to restore from WAL in an existing postgres installation.
Why does the log say that it cannot find 0000000A.history and 0000000A00000000000000CC files? The folder does not contain any such files.
Can anyone help us with this?
Thanks.
Sarthak

Postgresql startup failure

I'm attempting to build a box via Fabric on Openstack. Part of the install involves installing and running PostgreSQL.
This command works fine:
$ sudo service postgresql initdb
This command fails:
$ sudo service postgresql start
Log output of failure shows no issues when I run this command:
$ cat /var/lib/pgsql/pgstartup.log
This command shows the following messages:
$ cat /var/lib/pgsql/data/pg_log/postgresql-Wed.log
LOG: could not open configuration file
"/var/lib/pgsql/data/pg_hba.conf": Permission denied
FATAL: could not load pg_hba.conf
My user while executing these commands has the following groups:
vagrant, wheel
My user is in the sudoers list under /etc/sudoers with these permissions:
vagrant ALL=(ALL) NOPASSWD: ALL
perms on pgsql:
[root#integration ~]# ls -ltr /var/lib/pgsql/
total 12
drwx------. 2 postgres postgres 4096 Sep 13 2012 backups
-rw-------. 1 postgres postgres 1152 Jun 19 20:17 pgstartup.log
drwx------. 12 postgres postgres 4096 Jun 19 20:19 data
and sub dir data:
[root#integration ~]# ls -ltr /var/lib/pgsql/data/
total 76
-rw-------. 1 postgres postgres 4 Jun 19 20:17 PG_VERSION
drwx------. 2 postgres postgres 4096 Jun 19 20:17 pg_twophase
drwx------. 2 postgres postgres 4096 Jun 19 20:17 pg_tblspc
drwx------. 2 postgres postgres 4096 Jun 19 20:17 pg_stat_tmp
drwx------. 4 postgres postgres 4096 Jun 19 20:17 pg_multixact
-rw-------. 1 postgres postgres 16886 Jun 19 20:17 postgresql.conf
-rw-------. 1 postgres postgres 1631 Jun 19 20:17 pg_ident.conf
drwx------. 3 postgres postgres 4096 Jun 19 20:17 pg_xlog
drwx------. 2 postgres postgres 4096 Jun 19 20:17 pg_subtrans
drwx------. 2 postgres postgres 4096 Jun 19 20:17 pg_clog
drwx------. 5 postgres postgres 4096 Jun 19 20:17 base
drwx------. 2 postgres postgres 4096 Jun 19 20:17 global
-rw-------. 1 postgres postgres 241 Jun 19 20:17 pg_hba.conf
drwx------. 2 postgres postgres 4096 Jun 19 20:17 pg_log
-rw-------. 1 postgres postgres 57 Jun 19 20:19 postmaster.opts
This turned out to be an selinux issue.
I disabled it and was well. Full config below.
For those of you that arent up on selinux (like me until today) the config can be found in:
/etc/selinux/config
It can also be turned off temporarily like this:
echo 0 > /selinux/enforce
Full config
[root#integration selinux]# cat config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.

postgres cannot access the server configuration file: Permission denied

This is baffling me (trying to set up postgres on MacOS Lion):
delirium:$ sudo ls -al /usr/local/pgsql/data/
total 64
drwx------ 15 postgres postgres 510 25 May 10:36 .
drwxr-xr-x# 13 103 103 442 25 May 10:35 ..
-rw------- 1 postgres postgres 4 25 May 10:36 PG_VERSION
drwx------ 5 postgres postgres 170 25 May 10:36 base
drwx------ 41 postgres postgres 1394 25 May 10:36 global
drwx------ 3 postgres postgres 102 25 May 10:36 pg_clog
-rw------- 1 postgres postgres 3652 25 May 10:36 pg_hba.conf
-rw------- 1 postgres postgres 1631 25 May 10:36 pg_ident.conf
drwx------ 4 postgres postgres 136 25 May 10:36 pg_multixact
drwx------ 2 postgres postgres 68 25 May 10:36 pg_stat_tmp
drwx------ 3 postgres postgres 102 25 May 10:36 pg_subtrans
drwx------ 2 postgres postgres 68 25 May 10:36 pg_tblspc
drwx------ 2 postgres postgres 68 25 May 10:36 pg_twophase
drwx------ 4 postgres postgres 136 25 May 10:36 pg_xlog
-rwxr-xr-x 1 postgres postgres 16879 25 May 10:36 postgresql.conf
delirium:$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
postgres cannot access the server configuration file "/usr/local/pgsql/data/postgresql.conf": Permission denied
Doesn't the output show that postgres is the owner of postgresql.conf? So why can't it access the file?
What can I do?
The quickest way to diagnose a permission denied error is to login (su or sudo) as that user and try to cat the file.
If this is permission denied and not file not found, I'm guessing the postgres user has not got execute permissions on one of the parent directories, it could be any of the 3: /usr/local/pgsql/
sudo -u postgres /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
...assuming postgres was set up with default user postgres