@@ -137,6 +137,83 @@ If you want to use :meth:`.visualize` or run the test suite, the Graphviz progra
137137If you install MESSAGEix :ref: `using conda <using-conda >`, Graphviz is installed automatically via `its conda-forge package `_.
138138For 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+
140217Install |MESSAGEix |
141218===================
142219
0 commit comments