I apologize for the long post. I have a Postgresql 9.3 server running on a Amazon linux AMI. I also have a compressed dump file from another server which I created using pg_dumpall. Now, I want to restore the data from this dump file in my Postgres. However, I want to load this data into a specific location (say /data).
I'm having a fresh installation of Postgres. So when I tried to do a:
sudo service postgresql93 start
I got an error message asking me to initialize the db. So I did a:
sudo service postgresql initdb
which created the required files in /var/lib/pgsql93/data. After that, I changed the 'data_directory' configuration in /var/lib/pgsql93/data/postgresql.conf and pointed it to /data (I had to do this as root user. I couldn't open the file as the default user).
Now when I try to do a
sudo service postgresql93 start
it fails to start, and when I check the /var/lib/pgsql93/pg_startup.log file, it says:
FATAL: "/data/postgresql" is not a valid data directory
DETAIL: File "/data/postgresql/PG_VERSION" is missing.
So I copied the files from the default (/var/lib/pgsql9.3/data) to /data, changed the permissions to 700 and owner to postgres.
However, when I try to start the service again, it still fails, and in the pgstartup.log, it only says:
LOG: redirecting log output to logging collector process
HINT: Future log output will appear in directory "pg_log".
And when I check the log in /data/pg_log, it says:
LOG: database system was shut down at 2014-12-30 21:31:18 UTC
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
What else could be the problem? I haven't restored the data yet. I just have the files which were created by the initdb command.
#BMW http://www.linuxquestions.org/questions/linux-server-73/change-postgresql-data-directory-649911/ is exactly what I was looking for. Thanks.
Related
I've followed the instructions to set up a replica server of PostgreSQL with repmgr, But I can't start the PostgreSQL service because of a permission problem.
On the stand by server, I have this on my /etc/repmgr.conf file:
node_id=2
node_name=aws-replica
conninfo='host=<REDACTED> user=repmgr dbname=repmgr port=5432'
data_directory='/mnt/data/postgres/data'
log_file='/var/log/repmgr.log'
As you can see, I've changed the location of the data directory to /mnt/data/postgres/data and also updated the postgresql.conf file with the same information.
When I try to start the PostgreSQL service, I get this error on journalctl:
FATAL: data directory "/mnt/data/postgres/data" has wrong ownership
HINT: The server must be started by the user that owns the data directory.
The folder in question is owned by a normal user, the same one that runs repmgr. If I set the ownership of the folder to postgres:postgres, then repmgr can't perform any operations because it can't access the folder. I tried joining the postgres group, but the service won't start unless the folder has 700 permissions, so it's pointless to join the group.
So, I'm either not being able to start postgresql or repmgr. What can I do to make it work?
The problem was that I created a postgres DB using innitdb, which wasn't necessary. I deleted the database and then ran repmgr as the postgres user, and it worked.
I'm using DBeaver to connect the postgres db and want to access the logs via DBeaver.
I run the command below to find log destination and got stderr as the location.
show log_destination ;
How can I reach that file on DB app? FYI, I want all logs, not the logs that are from DBeaver.
On recent PostgreSQL versions, that is simple:
SELECT pg_current_logfile();
For old versions, proceed as follows:
Verify that the logging collector is started:
SHOW logging_collector;
If not, the location of the log depends on how PostgreSQL was started.
If yes, the log will be in log_directory:
SHOW log_directory;
If that is a relative path, it is relative to the PostgreSQL data directory.
Since the log file is on the database server, you probably won't be able to access it with a client tool.
https://tableplus.com/blog/2018/10/how-to-show-queries-log-in-postgresql.html#:~:text=The%20location%20of%20the%20log,pgsql%2Fdata%2Fpg_log%2F%20.
In Ubuntu is under /var/log/postgresql
You can run pg_lsclusters.
> pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
11 main 5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
I need to get databases from the old PostgreSQL folder that was in Program Files (win 10).
I tried changing the data path through the registry (ImagePath
value after "-D" at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\postgresql-x64-12) from the current to the old PostgreSQL data folder.
I also tried replacing files in the current folder from PostgreSQL with old ones (replaced data for C:\Program Files\PostgreSQL\12\data\base and C:\Program Files\PostgreSQL\12\data\global).
In both cases, an error occurred when trying to start the postgresql-x64-12 service. Error message: the postgresql-x64-12 service on local computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
How can I get databases from old ../Program Files/PostgreSQL folder?
After replacing the folders C:\Program Files\PostgreSQL\12\data\base and C:\Program Files\PostgreSQL\12\data\global with the old ones and attempts to start the postgresql-x64-12 service, a log file appeared with the following content:
LOG: database system was shut down at ...
LOG: invalid primary checkpoint record
PANIC: could not locate a valid checkpoint record
LOG: startup process (PID 17452) was terminated by exception 0xC0000409
HINT: See C include file "ntstatus.h" for a description of the hexadecimal value.
LOG: aborting startup due to startup process failure
LOG: database system is shut down
Because of the message PANIC: could not locate a valid checkpoint record, I used pg_resetwal: in PowerShell I opened the folder C:\Program Files\PostgreSQL\12\bin, then ran the command .\pg_resetwal.exe -f -D "C:\Program Files\PostgreSQL\12\data. In some cases, it is worth using the command without -f, also for other versions of Postgres a different command may be needed. More information: https://stackoverflow.com/a/8812934/14145682.
After that, the service also did not start, and the following error was present in the log:
FATAL: could not access status of transaction
DETAIL: Could not read from file "pg_multixact/members/0000" at offset 8192: read too few bytes.
So, I replaced the files in the C:\Program Files\PostgreSQL\12\data\pg_multixact folder with the old ones.
After these steps, the postgresql-x64-12 service started without errors and it was possible to restore the old database.
I have installed postgres 9.5 in my linux(16.04) machine.I have started service using below command.
sudo service postgresql start
This will start postgres service as a postgres user.
But I want to run postgres a different user(myown user).
How can I do .Please help !!.
You have to recursively change the ownership of the database directory to the new user.
If the WAL directory or tablespaces are outside the data directory, you have to change their ownership too.
Then you will have to configure the startup script so that it starts PostgreSQL as the new user. Watch out: if you installed the startup script with an installation package, any changes to it will probably be lost after an update.
I recommend that you don't do all that and continue running PostgreSQL as postgres.
What I am trying to accomplish is a recovery using a continuous archive backup.
I am running a vm of CentOS 6.8 and Postgres 9.1 Postgres 9.1 is the same as the DB that I am pulling from.
I installed Postgres and initialized the DB, started up fine.
Then, following these directions: https://www.postgresql.org/docs/9.3/static/continuous-archiving.html
Stopped the destination pSQL server (as root: service postgresql-9.1 stop)
Copied the destination cluster data folder to the side (as postgres)
Removed the cluster data files (as postgres)
Copied in my source data folder (as postgres)
Copied WAL files into a clean pg_xlog folder under the data folder (as postgres)
Created a recovery.conf file which contained:
restore_command = 'cp /var/lib/pgsql/database_sample_backup/wal_archives/0A/%f %p'
This being another location for the WAL files other than the copy I placed in pg_xlog (was not sure if I needed both)
But when I attempt to restart my server, it fails. (as root: service postgresql-9.1 start)
My pgstartup.log at one point spit out "runuser: cannot set groups: Operation not permitted" but it doesn't consistently do this with every attempt to start.
I've also tried turning off archiving and replication directive in postgres.conf (so that it can run stand alone) and tried copying over the pg_hba.conf from the new DB I had created to see if they would resolve the issue. Neither did.
I've also done a netstat -ntap | grep 5432 which confirmed that I don't have anything else running on the port.
What else can I provide in the form of details, and what else my I attempt in this restoration process.
Thank you for your help!