Skip to content

Commit

Permalink
Merge pull request #4010 from GeotrekCE/improve_doc_postgres_upgrade
Browse files Browse the repository at this point in the history
Improve postgres upgrade doc
  • Loading branch information
submarcos committed Mar 21, 2024
2 parents 301ea72 + cdfd0e0 commit 8a867fe
Showing 1 changed file with 12 additions and 42 deletions.
54 changes: 12 additions & 42 deletions docs/install/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,42 +122,6 @@ Restore files on the new server:
tar xvzf data.tgz


Ubuntu bionic PostGIS 2.5 upgrade
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Geotrek-admin requires at least PostGIS 2.5.

If you installed Geotrek-admin on bionic ubuntu with provided install method, you should update your database :
::

# Firstly, backup your database (see previous section)
# install postgresql APT repository
# (from https://wiki.postgresql.org/wiki/Apt)

sudo apt install curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt update

# install postgis 2.5 on postgresql 10
sudo apt install postgresql-10-postgis-2.5-scripts
sudo -u postgres psql -d geotrekdb -c "ALTER EXTENSION POSTGIS UPDATE"; # replace geotrekdb by your database name

# You database is now using postgis 2.5 !

# Troubleshooting
# If you encounter error with last command to update postgis, just drop view v_projects and retry
# This view will be recreated after next Geotrek-admin upgrade or dpkg-reconfigure.
sudo -u postgres psql -d geotrekdb -c "DROP VIEW v_projects;";
sudo -u postgres psql -d geotrekdb -c "ALTER EXTENSION POSTGIS UPDATE";

# Warning, by using postgresql official apt repo, next apt upgrade or apt full-upgrade will install postgresql-9.6 and postgis 3 along your database, because postgis meta-package has changed
# If your are not using postgresql-9.6, you can remove it (bionic postgresql default version is 10)
# sudo apt remove postgresql-9.6

If you use an external database, you should adapt this method along your system


PostgreSQL
~~~~~~~~~~

Expand Down Expand Up @@ -211,19 +175,19 @@ Update PostgreSQL / PostGIS on Ubuntu Bionic

::

sudo rm /etc/apt/sources.list.d/pgdg.list
sudo rm -f /etc/apt/sources.list.d/pgdg.list
sudo apt install curl ca-certificates
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt-archive.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt update


Then, make a database dump.
Then, make a database dump. You can see user / database / password in /opt/geotrek-admin/conf/env file.

::

sudo -u postgres pg_dump -Fc --no-acl --no-owner -d <your geotrek database name> > /path/to/your/backup.dump
sudo -u postgres pg_dump -Fc --no-acl --no-owner -d <your geotrek database name> > ./backup.dump


Now, install newest version of PostgreSQL and PostGIS:
Expand Down Expand Up @@ -260,12 +224,12 @@ Recreate user and database:

.. warning::

You should report configuration from /etc/postgresql/10/pg_hba.conf to /etc/postgresql/14/pg_hba.conf.
You should report configuration from /etc/postgresql/10/main/pg_hba.conf to /etc/postgresql/14/main/pg_hba.conf.
Then restart your postgresql

::

sudo cp /etc/postgresql/10/pg_hba.conf /etc/postgresql/14/pg_hba.conf
sudo cp /etc/postgresql/10/main/pg_hba.conf /etc/postgresql/14/main/pg_hba.conf
sudo systemctl restart postgresql


Expand All @@ -274,7 +238,13 @@ You can now restore your database dump.

::

pg_restore -p 5433 -U <your geotrek user> -d <your geotrek database> /path/to/your/backup.dump
pg_restore -h 127.0.0.1 -p 5433 -U <your geotrek user> -d <your geotrek database> ./backup.dump

.. note::

Note you have to use `-h 127.0.0.1` to connect with the `geotrek` user (this user cannot connect with the default unix socket). Connecting with `geotrek` is important for restored entities to have the right owner.
Some errors can occurs, around extensions creation or spatial_ref_sys table content.
This is normal. We already create these extensions on previous steps.


.. warning::
Expand Down

0 comments on commit 8a867fe

Please sign in to comment.