Upgrading from postgres 14 beta to postgres 14 new release - postgresql

I installed postgres 14 beta and i want to upgrade to 14 new release. I have just installed the new release pg 14 and when i try to start the pg 14 beta i get the error below. May i know the correct procedure of upgrading from beta to new release
-bash-4.2$ /usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data -l logfile start
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
-bash-4.2$ cat logfile
2021-10-27 13:19:29.507 UTC [5112] FATAL: database files are incompatible with server
2021-10-27 13:19:29.507 UTC [5112] DETAIL: The database cluster was initialized with CATALOG_VERSION_NO 202106151, but the server was compiled with CATALOG_VERSION_NO 202107181.
2021-10-27 13:19:29.507 UTC [5112] HINT: It looks like you need to initdb.
2021-10-27 13:19:29.507 UTC [5112] LOG: database system is shut down

There has been a change in the catalog version since v14 beta 1, so you have to use fump/restore of pg_upgrade to upgrade.
Install 14.0, create a new cluster and use the method of your choice to upgrade.

Related

"error: pq: role "root" does not exist" when running pq with Postgres for Docker [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
I am setting up a local Postgres database on Docker with the postgres:14-alpine image, and running database migrations on it with golang-migrate, when I got the following error message after running the migrate tool:
error: pq: role "root" does not exist
I was running the following commands:
$ docker run --name postgres14 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=pass -d postgres:14-alpine
$ docker exec -it postgres14 createdb --user=root --owner=root demodb
$ migrate -path db/migrations -database postgresql://root:pass#localhost:5432/demodb?sslmode=disable --verbose up
These commands can also be viewed in this Makefile, and the full codebase can be found in this repository.
Here are the logs from the Postgres container:
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.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2022-10-15 09:56:41.209 UTC [36] LOG: starting PostgreSQL 14.5 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
2022-10-15 09:56:41.211 UTC [36] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-15 09:56:41.217 UTC [37] LOG: database system was shut down at 2022-10-15 09:56:41 UTC
2022-10-15 09:56:41.220 UTC [36] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down...2022-10-15 09:56:41.422 UTC [36] LOG: received fast shutdown request
.2022-10-15 09:56:41.423 UTC [36] LOG: aborting any active transactions
2022-10-15 09:56:41.423 UTC [36] LOG: background worker "logical replication launcher" (PID 43) exited with exit code 1
2022-10-15 09:56:41.424 UTC [38] LOG: shutting down
2022-10-15 09:56:41.434 UTC [36] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
What should I do to configure the root role correctly?
The docker image docs specify that POSTGRES_USER environment variable defaults to postgres if not set, try using that instead of root or drop the container and build it again using the correct environment variable
once you are inside the psql shell you can create a user with
CREATE USER username WITH PASSWORD 'your_password';
then to grant the user access on a specific database:
GRANT ALL PRIVILEGES ON DATABASE demodb TO username;
once that is done you can use the user in the connection string in make file
Turns out the Postgres server that was installed and setup on my OS by Hombrew was using the same port, which clashed with the requests made to the containerized database under the same port number.
This issue can be solved by either using a different port number for the containerized database, or by shutting down the database on the OS.

Dockerized PostgreSQL error with USE_FLOAT8_BYVAL on RPI3

I try to reinstall PostgreSQL with the official image : postgres:11.4-alpine.
Before, this image worked, but I had to reinstall the host OS (Alpine 3.16) on my Raspberry PI 3, and now, my DB is not working.
I installed Alpine 3.16 (RPI version) in diskless mode (wasn't before).
The PG container shows this error :
PostgreSQL Database directory appears to contain a database; Skipping initialization
2022-06-12 09:00:46.256 UTC [1] FATAL: database files are incompatible with server
2022-06-12 09:00:46.256 UTC [1] DETAIL: The database cluster was initialized with USE_FLOAT8_BYVAL but the server was compiled without USE_FLOAT8_BYVAL.
2022-06-12 09:00:46.256 UTC [1] HINT: It looks like you need to recompile or initdb.
2022-06-12 09:00:46.257 UTC [1] LOG: database system is shut down
Additional information :
uname -a
Linux srv-rp3 5.15.41-0-rpi2 #1-Alpine SMP Sat May 21 06:57:56 UTC 2022 armv7l Linux
I tried to rebuild image from my RPI but it doesn't change anything (https://github.com/docker-library/postgres/blob/899a216e56e49ca7ab1aaae937f1220caace7ce4/11/alpine/Dockerfile)
I tried adding --disable-float8-byval \ and --enable-float8-byval \ to the ./configure command (line 88) but it doesn't change anything...
https://github.com/docker-library/postgres/blob/899a216e56e49ca7ab1aaae937f1220caace7ce4/11/alpine/Dockerfile#L81
Many thanks

brew postgresql-upgrade-database fails on migrating and upgrading data

I've just sit down to my work, forgetting that I've upgraded brew in the 2020 – so of course I have a postgresql problem.
The last version I had was 12.x. Now I have 13.1 installed:
$ brew info postgres
Warning: Treating postgres as a formula. For the cask, use homebrew/cask/postgres
postgresql: stable 13.1 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
/usr/local/Cellar/postgresql/13.1 (3,217 files, 42.6MB) *
Poured from bottle on 2020-12-26 at 14:36:54
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgresql.rb
License: PostgreSQL
==> Dependencies
Build: pkg-config ✔
Required: icu4c ✔, krb5 ✔, openssl#1.1 ✔, readline ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
https://www.postgresql.org/docs/13/app-initdb.html
To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
==> Analytics
install: 181,394 (30 days), 574,628 (90 days), 1,984,700 (365 days)
install-on-request: 176,623 (30 days), 554,629 (90 days), 1,910,250 (365 days)
build-error: 0 (30 days)
Following the output, I'm trying to run brew postgresql-upgrade-database, but it does not work – here is the output:
$ brew postgresql-upgrade-database --debug --verbose
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/postgresql.rb
==> Upgrading postgresql data from 12 to 13...
/usr/local/Cellar/postgresql#12/12.5/bin/pg_ctl -w -D /usr/local/var/postgres start
waiting for server to start....2021-01-04 17:37:33.282 CET [8190] FATAL: database files are incompatible with server
2021-01-04 17:37:33.282 CET [8190] DETAIL: The database cluster was initialized with PG_CONTROL_VERSION 1300, but the server was compiled with PG_CONTROL_VERSION 1201.
2021-01-04 17:37:33.282 CET [8190] HINT: It looks like you need to initdb.
2021-01-04 17:37:33.282 CET [8190] LOG: database system is shut down
stopped waiting
pg_ctl: could not start server
Examine the log output.
==> Moving postgresql data from /usr/local/var/postgres to /usr/local/var/postgres.old...
==> Creating database...
/usr/local/opt/postgresql/bin/initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "nyc".
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".
Data page checksums are disabled.
fixing permissions on existing directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Warsaw
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: 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:
/usr/local/opt/postgresql/bin/pg_ctl -D /usr/local/var/postgres -l logfile start
==> Migrating and upgrading data...
/usr/local/opt/postgresql/bin/pg_upgrade -r -b /usr/local/Cellar/postgresql#12/12.5/bin -B /usr/local/opt/postgresql/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres -j 4
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
The source cluster was not shut down cleanly.
Failure, exiting
Error: Upgrading postgresql data from 12 to 13 failed!
==> Removing empty postgresql initdb database...
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres...
Error: Failure while executing; `/usr/local/opt/postgresql/bin/pg_upgrade -r -b /usr/local/Cellar/postgresql#12/12.5/bin -B /usr/local/opt/postgresql/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres -j 4` exited with 1.
/usr/local/Homebrew/Library/Homebrew/utils.rb:303:in `safe_system'
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/cmd/postgresql-upgrade-database.rb:126:in `block in postgresql_upgrade_database'
/usr/local/Homebrew/Library/Homebrew/extend/pathname.rb:318:in `block in cd'
/usr/local/Homebrew/Library/Homebrew/extend/pathname.rb:318:in `chdir'
/usr/local/Homebrew/Library/Homebrew/extend/pathname.rb:318:in `cd'
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/cmd/postgresql-upgrade-database.rb:125:in `postgresql_upgrade_database'
/usr/local/Homebrew/Library/Homebrew/brew.rb:124:in `<main>'
How can I fix this?

postgresql error up when running sudo service postgresql start under Ubuntu 20.04

As a PostgreSQL newbie user, I am getting this error below, when running sudo service postgresql start.
* Starting PostgreSQL 12 database server * Error: /usr/lib/postgresql/12/bin/pg_ctl /usr/lib/postgresql/12/bin/pg_ctl start -D /var/lib/postgresql/12/main -l /var/log/postgresql/postgresql-12-main.log -s -o -c config_file="/etc/postgresql/12/main/postgresql.conf" exited with status 1:
2020-10-01 15:58:42.129 EDT [6750] LOG: starting PostgreSQL 12.4 (Ubuntu 12.4-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, 64-bit
2020-10-01 15:58:42.131 EDT [6750] LOG: could not bind IPv4 address "127.0.0.1": Permission denied
2020-10-01 15:58:42.131 EDT [6750] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-10-01 15:58:42.131 EDT [6750] WARNING: could not create listen socket for "localhost"
2020-10-01 15:58:42.131 EDT [6750] FATAL: could not create any TCP/IP sockets
2020-10-01 15:58:42.132 EDT [6750] LOG: database system is shut down
pg_ctl: could not start server
Examine the log output.
The issue was because I installed postgresql without specifying the version so uninstalling and reinstalling with the version specified fixed the issue
To uninstall
sudo apt-get remove --purge postgresql-12
and then to reinstall
sudo apt-get install postgresql-12

psql : connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I have installed postgresql and done all the setup and created db and tables yesterday but today morning I got sudden this error
I have also uninstalled and installed postgresql but still same error. And also I have observed that when installed freshly it is working fine but once I shutdown or restart my system I'm getting the below error.
psql:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I have tried all the solutions given in all the mediums but I'm not able to resolve the issue so I'm posting this question again with my outputs.
The status of postgresql
**sudo /etc/init.d/postgresql status**
postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2019-10-30 11:40:39 IST; 5min ago
Process: 7666 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 7666 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/postgresql.service
When I run the pg_lsclusters
**pg_lsclusters**
Ver Cluster Port Status Owner Data directory Log file
11 main 5432 down postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
**dpkg -l | grep postgres**
ii pgdg-keyring 2018.2 all keyring for apt.postgresql.org
ii postgresql 11+207.pgdg16.04+1 all object-relational SQL database (supported version)
ii postgresql-11 11.5-3.pgdg16.04+1 amd64 object-relational SQL database, version 11 server
ii postgresql-client-11 11.5-3.pgdg16.04+1 amd64 front-end programs for PostgreSQL 11
ii postgresql-client-common 207.pgdg16.04+1 all manager for multiple PostgreSQL client versions
ii postgresql-common 207.pgdg16.04+1 all PostgreSQL database-cluster manager
ii postgresql-contrib 11+207.pgdg16.04+1 all additional facilities for PostgreSQL (supported version)
I even tried to restart the postgres still same issue.
**sudo /etc/init.d/postgresql status**
I had exactly this error message, and this is how I resolved it.
In the log file at /var/log/postgresql/postgresql-13-main.log, these lines were present:
2021-09-15 08:26:04.936 UTC [46258] LOG: invalid value for parameter "lc_messages": "en_US.UTF-8"
2021-09-15 08:26:04.936 UTC [46258] LOG: invalid value for parameter "lc_monetary": "en_US.UTF-8"
2021-09-15 08:26:04.937 UTC [46258] LOG: invalid value for parameter "lc_numeric": "en_US.UTF-8"
2021-09-15 08:26:04.937 UTC [46258] LOG: invalid value for parameter "lc_time": "en_US.UTF-8"
2021-09-15 08:26:04.937 UTC [46258] FATAL: configuration file "/etc/postgresql/13/main/postgresql.conf" contains errors
pg_ctl: could not start server
Examine the log output.
This is caused by missing locales, with these possible fixes:
localedef allegedly fixes this according but I had no luck with this.
localedef -i en_US -f UTF-8 en_US.UTF-8
change postgresql.conf and use a locale that does exist (en_GB in my case)
lc_messages = 'en_GB.UTF-8' # locale for system error message strings
lc_monetary = 'en_GB.UTF-8' # locale for monetary formatting
lc_numeric = 'en_GB.UTF-8' # locale for number formatting
lc_time = 'en_GB.UTF-8' # locale for time formatting
post settings
port = 5432 # (change requires restart)
Port was wrong on my PostgreSQL 13 default config (was 5433) and required a change back to the default 5432. I presume this was a result of upgrading from v11 so it gave it a new port number.
After these changes, PostgreSQL needs to restart and it should now function correctly without errors in the log, and the psql command working as expected.
Try this:
sudo -u postgres -i
And then:
initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data/'
exit
This has worked for me so far