postgresql upgrade backup and restore same port - postgresql

Here, I want to upgrade postgresql from 8.3(port 5432) to 9.0(port 5433)
Whats happen if,
-First I instal the postgres new version 9.0 on port 5433
-Than I backup and restore database by using comman,
/usr/local/pgsql/bin/ pg_dumpall -U -h -p 5432|psql -U -p 5433 -h
-After that I stop both server 8.3 and 9.0
-By using pgAdmin III, I change port the server 9.0 from 5433 to 5432.
Whats happen if I try to upgrade with that way?
thanks :)

This would work. This should also be faster than writing to file, as less writes will be needed. But remember to put old database in single user mode (postgres --single ...) so nobody would write to the database during migration.
You can also use pg_upgrade to upgrade database in place. But check for limitations while upgrading from 8.3.

As Tometzky has already said, this should work.
Just to make the picture complete:
With 9.0 you can also use pg_upgrade for the migration which should be even faster than using pg_dump with a pipe.

Related

postgresql - psql always goes to port 5432, even when 2 versions of postgresql are running

I have 2 versions of postgresql running on Suse SLES, 9.6 and 10.7. The 9.6 version is running on port 5432, and 10.7 is running on port 5433. All the executables for each version are in the directory for that version, including psql.
If I execute the default psql, I get psql for version 9.6.3:
psql (9.6.3)
However, when I try to execute psql for version 10.7:
/usr/pgsql-10/bin/psql
it opens the version for 10.7, but reading from postgresql 9.6.3:
psql (10.7, Server 9.6.3).
If I try to give it the port number for 10.7:
/usr/pgsql-10/bin/psql -p 5433
it demands a password, but rejects the password for the user postgres that I know works in other contexts.
I have spent considerable time searching for an answer to this question, and I am sorry I have not found anything helpful. Thanks for any suggestions!
There are two issues in play here.
1)
I su to postgres: su - postgres This requires a password, and the password that works here, does not work when psql wants/demands a password.
The OS postgres user is not the same as the database postgres user.
On a fresh install the database postgres user does not have a password. Generally speaking the auth method for the user is set to either trust, ident or peer. See here pg_hba.conf what they mean. The key to a solution is to modify the pg_hba.conf to allow the user to connect in order to be able to create a password. The easiest way is to set a connection method, best practice local(socket) to trust. Then you can connect without a password and create one.

Should I remove psql after postgres uninstalling from Mac M1?

I am trying to remove postgresql completely from my Mac M1 and then install postgres 13.
There were postgres 14, postgres 11 and postgres 13 installed (simultaneously) on my computer. Due to versions conflict I decided to remove all my postgreses and install version 13 de novo.
To uninstall postgres completely, I followed these recommendations: https://blog.testdouble.com/posts/2021-01-28-how-to-completely-uninstall-homebrew-postgres/
Now I have:
% postgres --version
zsh: command not found: postgres
% which postgresql
postgresql not found
% psql testdb
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory == NO DATABASES
%brew list also shows no postgres installed
but when I do
% psql --version
I see:
psql (PostgreSQL) 14.1
and
% which psql
/opt/homebrew/opt/libpq/bin/psql
So, I have front-end PostgreSQL 14 until now.
Is it normal that psql was not uninstalled with postgres server?
Of course some postgres files also remain in cache, as well as some Docker postgres images.
Should I remove postgresql14.1 client manually? Here I read that in such case after re-installation I can expect Error.
Or, in general: am I missing something that will prevent my computer from correct installing and running Postgres 13 locally and outside of Docker?
Thank you so much in advance for clarification.
Yes, Postgres client (psql) and PostgreSQL server are two separate software. Quite often you need psql in your workstation even if server is running somewhere else.
But if you don't need to connect any PostgreSQL server anymore from your workstation, you can remove psql. No harm done. And it is always easy to re-install if needed.

PostgreSQL: How to unify versions?

On my Kubuntu machine, locally I was running PostgreSQL in a user-defined directory. Actually, an upgrade from Kubuntu 18.04 to 20.04 provided PostgreSQL12. Actually, I have:
$ psql --version
psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)
$sudo -u postgres psql
[sudo] Passwort:
psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1), server 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1))
What do I have to do, to unify this (to version 12) without losing data in the user-defined directory? There are two version 10 packages (PostgreSQL-10 and PostgreSQL-client-10) and the same ones version 12: Is it OK and sufficient to remove the two from 10?
Thank you!
PostgreSQL is free to change how it stores data between versions. So just moving/copying the data directory is highly unlikely to be sufficient.
The simplest solution is to basically dump the data and then load it into the new server. If you start your new server running on a different port and different data directory, you can do this as one-liner.
pg_dumpall -p 5432 | psql -d postgres -p 5433
https://www.postgresql.org/docs/12/upgrading.html#UPGRADING-VIA-PGDUMPALL
If you have a lot of data, and you need to keep your database available during the upgrade then you may wish to look into logical replication.

Multiple installations of Postgres on Ubuntu

This is the first time I am setting up multiple Postgres postgres servers on Ubuntu 12.04LTS. (I know multiple versions is a bad idea, but need to sanity check new installation before I migrate and kill the old instance)
Original Postgres V9.1 is installed using bundled apt-get install. (Port : 5432)
New Postgres V10 is installed via EnterpriseDB package. (Port : 5433)
I am able to use standard utilities for the V9.1 like psql, pg_dump, etc. However, I am not able to access psql of V10. Instead I am getting this error message (note the incorrect port):
/opt/PostgreSQL/10/bin$ ./psqlpsql.bin: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I would like to be able to manage both ideally by using psql.
I usually use Python to connect to databases and I am able to create an SQLAlchemy connection to new instance at port 5433. I can query pg_catalog and information_schema as well.
Thanks in advance!
The default port of postgres is 5432.
So If you want to access psql of V10, use the below commands:
export PATH=/opt/PostgreSQL/10/bin:$PATH
psql -p 5433

PostgreSQL 9.4 database cannot be saved with pgAdmin 3 (Windows 8.1)

I am working with confuence under Windows 8.1 and have produced a lot of Input there.
Now I wanted to backup my PostgreSQL 9.4 database with pgAdmin 3.
I get the error:
C:\Program Files (x86)\pgAdmin III\1.18\pg_dump.exe --host localhost --port 5432 --username "postgres" --no-password --format custom --blobs --verbose --file "C:\Users\milenko\Desktop\output.backup" "confluence"
pg_dump: server version: 9.4.1; pg_dump version: 9.3.1
pg_dump: aborting because of server version mismatch
Do you know a solution?
You need to tell pgAdmin to use the 9.4 binaries, through the "Binary paths" section in the options dialog:
https://www.pgadmin.org/docs/pgadmin3/1.22.2/options-browser.html
your pgAdmin version is a bit old as well. 1.20 ships with Postgres 9.4, not 1.18
Also I found very effective to just replace pg_dump.exe in pgadmin version folder with my pg_dump.exe from my Postgres database.
I see why the solution above is better, but if someone would have problems with that, this also seems like functional alternative.
This solution above works fine for me!. You should try. Inside pgadmin folder, change pg_dump.exe name to pg_dump-bkp.exe and copy&paste pg_dump.exe from postgres folder.