Skip to content

Commit d7452ee

Browse files
authored
Merge pull request #981 from iiasa/enh/document-local-postgres-setup
Document how to setup a local Postgres DB
2 parents f97e386 + dbcb8af commit d7452ee

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

RELEASE_NOTES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ All changes
4848
- :mod:`message_ix.message_macro` includes :class:`.MESSAGE_MACRO`.
4949

5050
- Document the :ref:`minimum version of Java <install-java>` required for :class:`ixmp.JDBCBackend <ixmp.backend.jdbc.JDBCBackend>` (:pull:`962`).
51+
- Document :ref:`how to run a local PostgreSQL instance <install-postgres>`
52+
for local testing using :class:`ixmp.IXMP4Backend <ixmp.backend.ixmp4.IXMP4Backend>` (:pull:`981`).
5153
- Improve type hinting (:pull:`963`).
5254
- Fix capitalization in auxiliary_settings.gms to enable GDX output file compression on MacOS and Linux. (:pull:`965`)
5355

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def local_inv(name: str, *parts: str) -> str | None:
214214
"https://docs.messageix.org/projects/ixmp/en/latest/",
215215
(local_inv("ixmp"), None),
216216
),
217+
"ixmp4": ("https://docs.ece.iiasa.ac.at/projects/ixmp4/en/latest", None),
217218
"jpype": ("https://jpype.readthedocs.io/en/stable", None),
218219
"message-ix-models": (
219220
"https://docs.messageix.org/projects/models/en/latest/",

doc/install-adv.rst

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,83 @@ If you want to use :meth:`.visualize` or run the test suite, the Graphviz progra
137137
If you install MESSAGEix :ref:`using conda <using-conda>`, Graphviz is installed automatically via `its conda-forge package`_.
138138
For other methods of installation (such as :program:`pip`) see the `Graphviz download page`_ for downloads and instructions for your system.
139139

140+
.. _install-postgres:
141+
142+
PostgreSQL (optional)
143+
---------------------
144+
145+
.. caution::
146+
Support for PostgreSQL via :class:`ixmp.IXMP4Backend <ixmp.backend.ixmp4.IXMP4Backend>` experimental,
147+
and still under development.
148+
If you notice differences in behaviour or performance,
149+
please let us know by opening an issue on GitHub.
150+
151+
While the :mod:`ixmp4` package supports both SQLite and `PostgreSQL <https://www.postgresql.org/>`__ databases
152+
it and thus :class:`~ixmp.backend.ixmp4.IXMP4Backend` only provide complete support for |MESSAGEix| when using PostgreSQL.
153+
(See `iiasa/ixmp4#190 <https://github.com/iiasa/ixmp4/pull/190>`__ for details.)
154+
In order to use IXMP4Backend, ixmp4, and PostgreSQL for local storage of :class:`message_ix.Scenario` data,
155+
you must have a running instance of PostgreSQL.
156+
157+
There are multiple ways to install and configure PostgreSQL;
158+
`the ixmp4 developer documentation <https://github.com/iiasa/ixmp4/blob/main/DEVELOPING.md#running-tests-with-postgresql>`__ contains some discussion.
159+
One way that suffices for local testing is to use `Docker <https://docker.com>`__:
160+
161+
- Ensure Docker is installed.
162+
If necessary,
163+
follow the `the Docker install instructions <https://docs.docker.com/engine/install>`__.
164+
- Pull (retrieve) the latest version of the official PostgreSQL Docker image.
165+
In a terminal, run::
166+
167+
docker pull postgres
168+
169+
- Run the container::
170+
171+
docker run -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=ixmp_test -p 5432:5432 -d postgres
172+
173+
As of version 3.12, the :mod:`ixmp` default configuration includes a Platform named ``ixmp4-local``
174+
that uses IXMP4Backend with the setting :py:`dsn="postgresql+psycopg://postgres:postgres@localhost:5432/ixmp_test"`.
175+
In the above :program:`docker run` call,
176+
the particular values for the ``POSTGRES_PASSWORD`` and ``POSTGRES_DB`` environment variables
177+
result in a database instance that matches this setting.
178+
You may choose different values for these environment variables;
179+
if so, then use a setting like :py:`dsn="postgresql+psycopg://postgres:{POSTGRES_PASSWORD}@localhost:5432/{POSTGRES_DB}"`
180+
for the given Platform.
181+
182+
The container must continue running while using :mod:`message_ix` with any PostgreSQL-backed Platform(s).
183+
Afterwards:
184+
185+
- Show information about the running container(s)::
186+
187+
docker ps
188+
189+
This will show CONTAINER ID like "9d80a28ce850" and NAMES like "foo_bar".
190+
191+
- Stop the PostgreSQL container using either its ID or name::
192+
193+
docker stop [CONTAINER ID]
194+
195+
.. warning:: When the container is stopped
196+
—for instance, if the computer is turned off or rebooted—
197+
**no data is preserved**.
198+
In order for the contents of PostgreSQL database(s) in the container
199+
to persist across container restarts,
200+
the Docker :program:`--volume` option or similiar configuration must be used
201+
to 'mount' or 'bind' a directory outside the container.
202+
203+
.. todo:: Expand the above commands to include :program:`--volume` examples.
204+
205+
.. tip::
206+
If :mod:`ixmp4` is installed or available from source
207+
a `Docker Compose <https://docs.docker.com/compose/>`__ file,
208+
:file:`tests/docker-compose.yaml`
209+
(`view on GitHub <https://github.com/iiasa/ixmp4/blob/main/tests/docker-compose.yml>`__)
210+
is available.
211+
This allows to combine the :program:`docker pull` and :program:`docker run` steps
212+
and use enviroment variables set by the file contents.
213+
In a terminal, run::
214+
215+
docker-compose -f docker-compose.yml up
216+
140217
Install |MESSAGEix|
141218
===================
142219

0 commit comments

Comments
 (0)