pg_upgrade says it cannot write to log file pg_upgrade_internal.log but there are some logs in that file - postgresql

During upgrade from PostgreSQL 8.4.8 to PostgreSQL 9.5.2 on Windows OS, i got the following error over command line:
Running in verbose mode
cannot write to log file pg_upgrade_internal.log
Failure, exiting
When I checked the file pg_upgrade_internal.log, it contained following data:
Running in verbose mode
-----------------------------------------------------------------
pg_upgrade run on Tue Apr 24 17:02:13 2018
-----------------------------------------------------------------
Other files like pg_upgrade_server.log , pg_upgrade_utility.log, pg_upgrade_server_start.log, which are generated by pg_upgrade utility, also contain partial data:
-----------------------------------------------------------------
pg_upgrade run on Tue Apr 24 17:02:13 2018
-----------------------------------------------------------------
If pg_upgrade utility failed to write (or in other words, did not have permission), then who wrote the above data ? I am sure that these logs were written by PostgreSQL utility only.
BTW, I have already checked the Stackoverflow, PostgreSQL site links (link1, link2, etc.) which describe the cannot write... error issue, but none of those links mention this issue/concern.

Adding this for reference even though the question is old.
I had the same problem as above and none of the solutions seemed to work.
In my case it seems that the issue was caused by using the machines "Administrator" user with a elevated cmd prompt. I "fixed" the problem by using a normal user, with the correct security permissions on the Postgres data directories.

Related

Creating a copy of the database in PostgreSQL

I'm trying to create the first copy of my database. I'm using PostgreSQL and Ubuntu 16+ with Django technology.
I found this documentation to create a copy:
I'm trying to export the entire database to a file so that I can add it to another server. I tried this:
pg_dump app_prod > test_copy
pg_dump --host=localhost --username=app --dbname=app_prod --file=testdb.sql
after selecting ls my directory can see the database. But by running eg WinSCP it is not visible.
How can I take these files, copy them to my Windows system and upload to another Ubuntu server?
I think that it is enough to make them visible in WinSCP. How can I do this?
EDIT:
drwxr-xr-x 3 postgres postgres 4096 Oct 4 08:06 9.5
-rw-rw-r-- 1 postgres postgres 3578964 Jan 18 10:46 test_copy
-rw-rw-r-- 1 postgres postgres 0 Jan 18 10:54 testdb.sql
It seems like this was resolved in the comments: you were looking at the wrong folder in the WinSCP folder explorer.
There are a few items worth noting to bolster the good advice already given:
Your ls -l output indicates that the SQL file is zero bytes in size, so something has gone wrong there. If you manage to transfer it to your local machine, you will find it is empty.
Also, try not to store database dumps in /var/lib/postgresql - this is where your PostgreSQL database keeps live database files on the server, and you don't want to risk changing or deleting anything here. Use /home/maddie instead (change the username as appropriate).

What is the /var/lib/postgresql/10/main/ equivilent in PSQL-12?

I'm working on setting up point in time backups for a PSQL server that I have running, and I'm following a tutorial for an earlier version. I'm trying to figure out what the specific directory is for the DB cluster in PSQL-12 so that I can clear out that directory and test what I've setup. In the video, he runs a recursive remove on the PSQL-10 directory /var/lib/postgresql/10/main, and is still able to start the PSQL-10 service again when he's finished the restoration.
When I attempted it, I ran the recursive remove on the directory /var/lib/pgsql/12/data/ because the command SHOW data_directory; told me that is where my server's cluster data is stored. Removing all the data, however, messes up the postgresql-12.service, so I can't start it back up when I've completed the recovery.
This is displayed when I restore the backup and run systemctl start postgresql-12.service:
Process: 26672 ExecStart=/usr/pgsql-12/bin/postmaster -D ${PGDATA} (code=exited, status=1/FAILURE)
Dec 31 11:07:29 localhost.localdomain systemd[1]: Failed to start PostgreSQL 12 data....
I've tried making a backup of the working /data/ directory and doing a diff -qr to see what files differ between the working backup and the point in time backup, but coping those files from the working directory to the PIT directory doesn't seem to fix the issue, and I'm still unable to start the postgresql-12.service. It seems, however, that I am able to start the service back up successfully if I just do a mass copy of the working directory to /var/lib/postgresql/10/main.
Can someone please point me in the right direction? I've done plenty of research trying to find the working cluster directory so I can just erase table information and work on a PIT recovery without messing up the core application prereqs (such as the service), but I can't seem to find the information I'm looking for. Any assistance would be greatly appreciated! Additionally, if there's a way to spot this directory more quickly in the future, either by a command or looking at the files within, I would love to know so I can implement this procedure on different PSQL versions. Thank you!

Postgres COPY TO not working for intended destination directory

I have written a function that prepares data based on user-input from the web and copies the results down as a csv to a specified directory, from where the package (each request will contain information from 3 different tables/csv files) will be made available for the user to download.
The function itself works if the output directory is in the pg_data directory /var/lib/pgsql/data/adc_downloads, the permissions are:
drwxr-xr-x 2 postgres postgres 4096 Dec 5 15:18 adc_downloads
But ideally I want the output directory to be here: /var/www/vhosts/[vhostname]/httpdocs/adc_downloads. After getting it to work in pg_data, I used chown -R --reference=/var/lib/pgsql/data/adc_downloads /var/www/vhosts/[vhostname]/httpdocs/adc_downloads and chmod with the same parameters to mimic the permissions which appears to have worked:
drwxr-xr-x 2 postgres postgres 4096 Dec 5 14:19 adc_downloads
but I'm still getting a Permission denied error when trying to run the function with the intended output directory.
Something else then must be overriding the permissions I've (tried to?) set, any ideas what this might be? Given the function itself works in one directory but not another I don't think it's an SELinux issue, though I may of course be wrong.
Version Info: Postgres 8.4 CentOS 6.5 built with Plesk.
got this working (thanks to #joop's recommendation) in the intended location /var/www/vhosts/[vhostname]/httpdocs/adc_downloads by adding execute permission for the other users (including the postgres user) for the [vhostname] and httpdocs directories

Postgresql query did not terminate, after restart the service postgresql doesn't start

At my work I was running a complex query. I cancelled it and went home yesterday. This morning in the back the query was impossible to be terminated, also with the 'terminate backend' functionality. A colleague of mine restarted the host machine where postgres is installed. After the machine restart, the postgres database sever would not start up.
In my log files I see the error:
'pg_ctl: this data directory appears to be running a pre-existing postmaster'
I am not sure how to handle this problem. I could try to fix it or try to extrapolate the data from the save files. What is the most logical step to take and do you know how to fix this?
Earlier it gave this error message :
2016-01-28 15:52:33 GMT FATAL: lock file "postmaster.pid" already exists
2016-01-28 15:52:33 GMT HINT: Is another postmaster (PID 2100) running in data directory "C:/PostgreSQL/9.1/data"?
UPDATE... I located the file postmaster.pid and deleted it. Now I am restarting the computer and hoping it will start.
UPDATE... It works now. I rebooted the computer and postgres just instantly started. Happy as a child but at the same time not fully satisfied because of the following forum: https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists . Here it is stated to NEVER delete the postmaster.pid because of possible data corruption. So because of that I will backup all databases I have in postgres now.
So if anyone can share some more light on my ICT adventure of today I would be very satisfied. That is why I will not state that this question is answered, since I have no idea what went wrong and perhaps will run into it again someday.
The explanation is pretty straightforward. PostgreSQL writes the process ID to a file called postmaster.pid — the presence of the file is supposed to indicate that the server is running. When the PostgreSQL shuts down cleanly, it removes the postmaster.pid file.
However, when your colleague restarted the host machine, the PostgreSQL server got killed without having had a chance to remove the postmaster.pid file. Therefore, when you tried to start PostgreSQL, the presence of the file made it look complain that the server was already running.
This answer provides more complete advice. In general, you should never delete postmaster.pid for no good reason, because it's supposed to help prevent two servers from running at once on the same data files. However, if you are certain that the process indicated by the postmaster.pid file is already dead, then by all means just delete the stale PID file manually.
In windows Delete all running postgres processes and start the service

What does the `--fresh` option do in Brew?

While following installation instructions (e.g., for caffe for os x), I run into the --fresh flag for homebrew. For example,
brew install --fresh -vd snappy leveldb gflags glog szip lmdb
However, I see no documentation about what --fresh does, and I don't find it in the source code for homebrew. What does this flag do? (Or what did it used to do?)
I found an old github issue describing the behavior of --fresh.
The flag was meant to ensure packages would be installed without any previously set compile-time options (like --with-python), but it was removed because it didn't do anything:
commit 64744646e9be93dd758ca5cf202c6605accf4deb
Author: Jack Nagel <jacknagel#gmail.com>
Date: Sat Jul 5 19:28:15 2014 -0500
Remove remaining references to "--fresh"
This option was removed in 8cdf4d8ebf439eb9a9ffcaa0e455ced9459e1e41
because it did not do anything.