odoo12 database backup no owner? - postgresql

I can't backup odoo 12 database, i use postgres 10 and docker containers.error:
Database backup error: Postgres subprocess ('/usr/bin/pg_dump', '--no-owner', '--file=/tmp/tmpgoyjsd3i/dump.sql', 'odoo') error 1

This error occurs if you have a different version of Postgresql client (the version on Odoo server) and server (the version on your database server). If you are using the Odoo "official" Docker image or image based on that, e.g. veivaa/odoo image, it is based on debian:stretch version and it has Postgresql version 9.6 as default client. With this setup you will have a mismatch: client v9.6 connecting to server v10. It will result in the error you are getting.
To solve this you have to install same version on client and server. You can either downgrade your Postgres server to 9.6, or upgrade Postgres client in your Odoo Docker container to 10. You can test this by doing the client upgrade manually. docker exec -ti -u 0 yourodoocontainername bash to the Odoo container and executing these commands inside the Odoo container:
apt-get update
echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' > /etc/apt/sources.list.d/pgdg.list
yes Y | apt-get install wget
yes Y | apt-get install gnupg
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
yes Y | apt-get install postgresql-client-10
You need to have root permissions in the container to run these. After this install you can exit from exec and restart your container with docker restart yourodoocontainername. Make sure you have persistent storage used for Odoo data so that you don't lose your filestore. After these steps you are able to do backups and restores with Odoo web interface.
You can check your Postgresql client version with psql --version command. The expected result with version 9.6 is psql (PostgreSQL) 9.6.10 and with version 10 psql (PostgreSQL) 10.6 (Debian 10.6-1.pgdg90+1).
The exec method is good for testing but not good for permanent use because it involves manual steps. You should build your Docker images with the right version by modifying your Dockerfile.

I also experience this error. It is because your odoo docker image has a different version of Postgresql than the odoo database PostgreSQL image. please make sure that both have the same version.
Steps
docker exec -ti -u 0 yourodoocontainername bash
psql --version
the above will give you the version of PostgreSQL in the odoo container
docker exec -ti -u 0 yourodoocontainername bash
psql --version
the above will give you the version of the PostgreSQL image
if the above two versions are different please use the following commands.
apt-get update
echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' > /etc/apt/sources.list.d/pgdg.list
yes Y | apt-get install wget
yes Y | apt-get install gnupg
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
yes Y | apt-get install postgresql-client-{virsion of your PostgreSQL image eg, 12 )

Related

How to upgrade postgresql database from 10 to 12 without losing data for openproject

My OpenProject management software is installed with default postgresql 10.
Currently the postgresql DB is 12, It is having lot of new features.
I want to upgrade my Postgres DB without losing the data in the DB.
My system is ubuntu 18.04 and hosted openproject.
I searched the internet and could not find a step by step to upgrade postgresql.
Can you please guide me to install new DB and all data should be in the new DB.
thanks for your help.
A) First create a backup of all the databases for that (You can continue from B if you dont need a backup)
Log in as postgres user
sudo su postgres
Create a backup .sql file for all the data you have in all the databases
pg_dumpall > backup.sql
B) Upgrade to PostgreSQL12
update packages and install postgres 12
sudo apt-get update
sudo apt-get install postgresql-12 postgresql-server-dev-12
Stop the postgresql service
sudo systemctl stop postgresql.service
migrate the data
/usr/lib/postgresql/12/bin/pg_upgrade \
--old-datadir=/var/lib/postgresql/10/main \
--new-datadir=/var/lib/postgresql/12/main \
--old-bindir=/usr/lib/postgresql/10/bin \
--new-bindir=/usr/lib/postgresql/12/bin \
--old-options '-c config_file=/etc/postgresql/10/main/postgresql.conf' \
--new-options '-c config_file=/etc/postgresql/12/main/postgresql.conf'
Switch to regular user
exit
Swap the ports the old and new postgres versions.
#change port to 5432
sudo vim /etc/postgresql/12/main/postgresql.conf
#change port to 5433
sudo vim /etc/postgresql/10/main/postgresql.conf
Start the postgresql service
sudo systemctl start postgresql.service
Log in as postgres user
sudo su postgres
Check your new postgres version
psql -c "SELECT version();"
Run the generated new cluster script
./analyze_new_cluster.sh
Return as a normal(default user) user and cleanup up the old version's mess
#uninstalls postgres packages
sudo apt-get remove postgresql-10 postgresql-server-dev-10
#removes the old postgresql directory
sudo rm -rf /etc/postgresql/10/
#login as postgres user
sudo su postgres
#delete the old cluster data
./delete_old_cluster.sh
Congrads! Your postgresql version is now upgraded, If everything works well in B, we dont have to apply the backup as we have already migrated the data from the older version to the newer version, the backup is just in case if anything goes wrong.
NOTE: Change the postgresql.conf and pg_hba.conf as per your requirement
PS: Feel free to comment your issues, suggestions or anyother modifications you would like to suggest
Backup the database
psql --version sudo -u postgres psql pg_dumpall > alldbs.sql
(this command will backup all databases from the postgresql db)
Then exit from postgres user, and:
Inside a terminal run these commands:
sudo systemctl stop postgres
sudo apt-get install -y postgresql-12 postgresql-server-dev-12 postgresql-contrib-12 libpq-dev postgresql-12-hypopg
sudo pg_dropcluster 12 main --stop
sudo pg_upgradecluster 10 main
sudo pg_dropcluster 10 main --stop
restart the postgresql service:
sudo systemctl restart postgresql
login to the postgres:
su - postgres
to check the version:
psql --version
I have done using the above steps and I could update the DBand restore all data.
Postgresql Upgrade using pg_upgrade
Step - 1 (Find the locale language and encoding of source Postgresql server)
Log in to Postgresql database as postgres user
Execute the query SHOW LC_COLLATE;
Step - 2 ( Stop the existing/source Postgresql server)
Find the running Postgresql service using $ sudo systemctl list-units | grep postgres
Stop the service $ sudo service postgresql-<source-version>.service stop
Step - 3 (Install target Postgresql server)
Configure repos and install (lot of tutorials available in google)
Step - 4 (Update the locale language and encoding)
$ /usr/pgsql-<target-version>/bin/initdb -D /var/lib/pgsql/<target-version>/data --locale=<add-your-encoding>
Step - 5 (Check the source to target upgrade has any potential issues)
Run the command as postgres user, $sudo su postgres
$ /usr/pgsql-<target-version>/bin/pg_upgrade --old-bindir /usr/pgsql-<source-version>/bin --new-bindir /usr/pgsql-<target-version>/bin --old-datadir /var/lib/pgsql/<source-version>/data --new-datadir /var/lib/pgsql/12/data --link --jobs=2 --check
If it's ok we can move to the next step, If not fix the issues before proceeding to the next step
Expected output: Clusters are compatible
Step - 6 (Upgrade the source to target Postgresql version using the link option)
link option is pretty faster than the migration
Run the command as postgres user, $sudo su postgres
$ /usr/pgsql-<target-version>/bin/pg_upgrade --old-bindir /usr/pgsql-<source-version>/bin --new-bindir /usr/pgsql-<target-version>/bin --old-datadir /var/lib/pgsql/<source-version>/data --new-datadir /var/lib/pgsql/<target-version>/data --link
Expected output: Upgrade Complete
Thanks.
ENJOY !!!

How to upgrade to PostgreSQL 11 for Ubuntu 18.04?

As the title suggests I want to upgrade my postgresql-10 to postgresql-11.
I'm using ubuntu-18.04.
You can follow this blog setup Postgresql-11 on Ubuntu. I found it easy and simple.
Add the PostgreSQL package repository on your Ubuntu machine
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main 11" | sudo tee /etc/apt/sources.list.d/pgsql.list
Add the GPG key of the PostgreSQL package repository:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Update APT and install postgresql-11
sudo apt update && sudo apt install postgresql-11
Upgrading Postgres to the latest version (currently 13), or to an intermediate version such as 11, should be done by running:
sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
This is documented on https://wiki.postgresql.org/wiki/Apt
This runs a bash script on your computer. See there if you wish to run the steps manually.
Once you have installed Postgres, the easiest way to upgrade on Ubuntu is with pg_upgradecluster.
Backup your data. You will dropping the database, so no games!
sudo -u postgres pg_dumpall > all.sql
Upgrade.
// Install latest Postgres. Use `postgresql-11` for v11 instead of `postgresql` for latest.
sudo apt-get install -y postgresql
// The install sets up a cluster, which needs then to be removed for the upgrade.
// Stop and remove the newly installed cluster. Use `11` instead of `13` for v11
sudo pg_dropcluster 13 main --stop
// Upgrade the db. Takes the OLD version and OLD schema as required arguments
sudo pg_upgradecluster 10 main
// Test. Once you are satisfied, remove OLD cluster.
sudo pg_dropcluster 10 main
Use this command:
sudo apt update && sudo apt install postgresql-11

docker - addressing environment variables used in parent image

I need to create plpythonu extension on the postgres:10.3 image. For this, I extended the image with an installation command:
FROM postgres:10.3
RUN apt update && apt install -y postgresql-plpython-10
Now I need to run a psql command create extension plpythonu;. But at this point the postgres server is not running yet, so when running docker build . I get an error:
Step 3/3 : RUN psql -c "create extension plpythonu;";
---> Running in 037066c120ea
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"?
How do I fit this command in? And is there a way to do this without copypasting the entire docker-entrypoint.sh from the original postgres image? Maybe there's a way to specify this in docker-compose?
When step-2 is over you Postgres database down, that is why in Step-3 database is not running.
You can combine step-2 and step-3 together.
RUN apt update && \
apt install -y postgresql-plpython-10 && \
psql -c "create extension plpythonu;"
It means && (logical and) if previous commands successfully over then only execute next one.

How to upgrade psql on Amazon ec2?

I'm aware of how one can upgrade the PostgreSQL version on an RDS instance by using the management console's point-and-click. However, doing so leaves me with mismatched client and server psql versions. I want to upgrade the psql client on my ec2 instance. How does one do so?
You can also use amazon-linux-extras command to install new major versions of postgresql, for example:
$ sudo amazon-linux-extras install postgresql13
$ psql --version
psql (PostgreSQL) 13.3
Note that previous versions will remain enabled, but you can explicitly disable them (even though there's no uninstall, try yum to get rid of packages):
$ sudo amazon-linux-extras disable postgresql11
Tested on:
$ hostnamectl | grep -E -w 'Operating|Kernel|Architecture'
Operating System: Amazon Linux 2
Kernel: Linux 4.14.243-185.433.amzn2.aarch64
Architecture: arm64
The exact solution is going to vary depending on your AMI, but here's what worked for me on Amazon Linux:
sudo yum erase postgresql92 -y
sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm -y
sudo yum install postgresql96 postgresql96-devel -y
sudo ln -sf /usr/pgsql-9.6/bin/pg_config /usr/bin/
You might not need the last step unless you're trying to get the pg gem working in Ruby on Rails.

cannot find adminpack.sql in postgresql 9.1

I'm trying to get it installed and use in ubuntu. Was following this page to install the additional instrumentation packages.
Install Server Instrumentation for Postgresql 8.4
To install Server Instrumentation for Postgresql 8.4 you may use the command line and type:
sudo apt-get install postgresql-contrib
Run the adminpack.sql script, simply type:
sudo -u postgres psql < /usr/share/postgresql/8.4/contrib/adminpack.sql
But I couldn't find adminpack.sql in 9.1 version.
In PostgreSQL 9.1 and later, extensions can be installed via the CREATE EXTENSION command:
sudo -u postgres psql
CREATE EXTENSION "adminpack";
Try locate adminpack. But first, run updatedb to make sure the locate database is up to date.
sudo updatedb
locate adminpack
The output is:
/usr/lib/postgresql/9.1/lib/adminpack.so
/usr/share/postgresql/9.1/extension/adminpack--1.0.sql
/usr/share/postgresql/9.1/extension/adminpack.control
Looks like this is old and comments are closed, so I'm opening another answer.
ldalonzo's answer is correct once you have all the components, but I found I also had to run:
sudo apt-get install postgresql-contrib-9.1
Looks like the bare postgresql package doesn't include the additional modules.
Once you install postgresql-contrib using below command
sudo apt-get install postgresql-contrib
Adminpack is located in the below path
/usr/share/postgresql/9.1/extension/adminpack--1.0.sql
To load the adminpack use the below command
sudo su postgres -c psql < /usr/share/postgresql/9.1/extension/adminpack--1.0.sql
Then
sudo /etc/init.d/postgresql restart