Skip to content
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ecb20a4
Add psycopg package.
clokep Nov 9, 2023
c7e3120
Method to set statement timeout.
clokep Nov 15, 2023
91ef287
Separate PostgresEngine into Psycopg2Engine and PsycopgEngine.
clokep Nov 9, 2023
0a06be1
Run tests in CI against psycopg.
clokep Nov 9, 2023
260a5b7
Update user directory to handle psycopg3.
clokep Oct 9, 2024
ce8ad96
Support execute_values on psycopg3.
clokep Oct 9, 2024
93b1740
Fix-up simple_* tests.
clokep Oct 10, 2024
d49827d
Fix-up calls to end_to_end_keys.
clokep Oct 10, 2024
287f0a6
Use superclass version of `executescript()` (#1)
realtyem Oct 17, 2024
9f77ac4
Switch out formatting placeholder for what psycopg2 is expecting (#2)
realtyem Oct 17, 2024
3bbd562
Merge remote-tracking branch 'upstream/develop' into psycopg3
clokep Oct 23, 2024
f5b6429
Linting (and a fix) (#3)
realtyem Oct 23, 2024
7ff4584
Merge remote-tracking branch 'refs/remotes/origin/psycopg3' into psyc…
clokep Oct 23, 2024
5353f8d
Try running complement builds?
clokep Oct 24, 2024
1bec3d7
Merge branch 'develop' into psycopg3
realtyem Jul 21, 2025
f6c2364
Adjust type: ignore line to where mypy will apply it
realtyem Jul 21, 2025
279791d
Add both PsycopgEngine and Psycopg2Engine to database.engines.__all__…
realtyem Jul 21, 2025
1ceb332
Adjust _mark_state_groups_as_pending_deletion_txn() to use execute_ba…
realtyem Jul 21, 2025
95eb7f8
Adjust set_profile_field() insertion sql for a narrower type on param…
realtyem Jul 22, 2025
4ad733f
Try an update to the config schema?
realtyem Jul 22, 2025
f65a885
Adjust unit tests to reflect updated minimal versions of python/postgres
realtyem Jul 22, 2025
425971f
Minor changes to profile field
clokep Sep 30, 2025
61a3aaa
Merge remote-tracking branch 'upstream/develop' into psycopg3
clokep Sep 30, 2025
f31d8d2
Newsfragment
clokep Sep 30, 2025
ad229a9
Merge remote-tracking branch 'upstream/develop' into psycopg3
clokep Sep 30, 2025
2f4352b
poetry lock again
clokep Sep 30, 2025
467a8c4
Merge branch 'develop' into psycopg3
clokep Oct 6, 2025
e59ea08
Merge branch 'develop' into psycopg3-adjust-settings
realtyem Nov 23, 2025
d9226e0
Update poetry.lock file
realtyem Nov 23, 2025
0693794
linting fixups
realtyem Nov 23, 2025
dcc4b5a
Merge pull request #4 from realtyem/psycopg3-adjust-settings
clokep Nov 25, 2025
c195ee6
Merge branch 'develop' into jason/psycopg-merge-develop
jason-famedly Jan 30, 2026
99ff2ac
Adjust for execute_values() usage with fetch=False to only be appropr…
jason-famedly Jan 30, 2026
698a56d
Attempt forcing a lower case comparison to "psycopg" in complement.sh
jason-famedly Jan 31, 2026
088ead3
Add mini docstrings to the abstract postgres engine class, as well as…
jason-famedly Jan 31, 2026
123aeac
I forgot that the new driver is not wired up in the complement script…
jason-famedly Feb 2, 2026
680ffee
Merge pull request #6 from jason-famedly/jason/psycopg-merge-develop
clokep Feb 3, 2026
4cd7924
Use the 'c' extra instead of the 'pure python' version for C-compiled…
jason-famedly Feb 3, 2026
a320d8a
Update 'c' extra to 3.2.8 as a minimum. This avoids olddebian's packa…
jason-famedly Feb 19, 2026
d94d4c0
Allow complement to be ran with WORKERS=1 and still allow the psycopg…
jason-famedly Feb 19, 2026
73415a2
Merge pull request #7 from jason-famedly/jason/adjust-for-feedback
clokep Feb 19, 2026
0e083b1
Merge branch 'develop' into jason/update-psycopg3
jason-famedly Mar 30, 2026
63c7f03
update poetry lock
jason-famedly Mar 30, 2026
0af6799
Merge branch 'develop' into jason/update-psycopg3
jason-famedly Apr 6, 2026
5c4f8a9
Merge pull request #8 from jason-famedly/jason/update-psycopg3
clokep Apr 6, 2026
efcb28c
Merge branch 'develop' into jason/update-poetry-lock
jason-famedly Apr 28, 2026
59cd733
Merge pull request #9 from jason-famedly/jason/update-poetry-lock
clokep Apr 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions .ci/scripts/calculate_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,38 @@ def set_output(key: str, value: str):
for version in ("3.10", "3.11", "3.12", "3.13")
)

# Run with both psycopg2 and psycopg.
trial_postgres_tests = [
{
"python-version": "3.9",
"database": "postgres",
"postgres-version": "13",
"extras": "all",
}
},
{
"python-version": "3.9",
"database": "psycopg",
"postgres-version": "13",
"extras": "all",
},
]

if not IS_PR:
trial_postgres_tests.append(
{
"python-version": "3.13",
"database": "postgres",
"postgres-version": "17",
"extras": "all",
}
trial_postgres_tests.extend(
[
{
"python-version": "3.13",
"database": "postgres",
"postgres-version": "17",
"extras": "all",
},
{
"python-version": "3.13",
"database": "psycopg",
"postgres-version": "17",
"extras": "all",
},
]
)

trial_no_extra_tests = [
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ jobs:
run: until pg_isready -h localhost; do sleep 1; done
- run: poetry run trial --jobs=6 tests
env:
SYNAPSE_POSTGRES: ${{ matrix.job.database == 'postgres' || '' }}
# If matrix.job.database is 'psycopg' set SYNAPSE_POSTGRES to that string;
# otherwise if it is 'postgres' set it to true. Otherwise, empty.
SYNAPSE_POSTGRES: ${{ matrix.job.database == 'psycopg' && 'psycopg' || matrix.job.database == 'postgres' || '' }}
SYNAPSE_POSTGRES_HOST: /var/run/postgresql
SYNAPSE_POSTGRES_USER: postgres
SYNAPSE_POSTGRES_PASSWORD: postgres
Expand Down Expand Up @@ -712,6 +714,9 @@ jobs:
- arrangement: workers
database: Postgres

- arrangement: workers
database: Psycopg

steps:
- name: Checkout synapse codebase
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Expand All @@ -738,7 +743,7 @@ jobs:
COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -p 1 -json 2>&1 | synapse/.ci/scripts/gotestfmt
shell: bash
env:
POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }}
POSTGRES: ${{ (matrix.database == 'Postgres' || matrix.database == 'Psycopg') && matrix.database || '' }}
WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }}
name: Run Complement Tests

Expand Down
1 change: 1 addition & 0 deletions changelog.d/18999.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support using psycopg as the PostgreSQL driver. Contributed by @clokep and @realtyem.
12 changes: 12 additions & 0 deletions docker/complement/conf/start_for_complement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ export SYNAPSE_REPORT_STATS=no
case "$SYNAPSE_COMPLEMENT_DATABASE" in
postgres)
# Set postgres authentication details which will be placed in the homeserver config file
export POSTGRES_DRIVER=psycopg2
export POSTGRES_PASSWORD=somesecret
export POSTGRES_USER=postgres
export POSTGRES_HOST=localhost

# configure supervisord to start postgres
export START_POSTGRES=true
;;

psycopg)
# Set postgres authentication details which will be placed in the homeserver config file
export POSTGRES_DRIVER=psycopg
export POSTGRES_PASSWORD=somesecret
export POSTGRES_USER=postgres
export POSTGRES_HOST=localhost
Expand Down
4 changes: 2 additions & 2 deletions docker/conf/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ listeners:

{% if POSTGRES_PASSWORD %}
database:
name: "psycopg2"
name: "{{ POSTGRES_DRIVER or "psycopg2" }}"
args:
user: "{{ POSTGRES_USER or "synapse" }}"
password: "{{ POSTGRES_PASSWORD }}"
database: "{{ POSTGRES_DB or "synapse" }}"
dbname: "{{ POSTGRES_DB or "synapse" }}"
{% if not SYNAPSE_USE_UNIX_SOCKET %}
{# Synapse will use a default unix socket for Postgres when host/port is not specified (behavior from `psycopg2`). #}
host: "{{ POSTGRES_HOST or "db" }}"
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ For more information on using Synapse with Postgres, see [here](../../postgres.m

This setting has the following sub-options:

* `name` (string): This option specifies the database engine to use: either `sqlite3` (for SQLite) or `psycopg2` (for PostgreSQL). If no name is specified Synapse will default to SQLite. Defaults to `"sqlite3"`.
* `name` (string): This option specifies the database engine to use: either `sqlite3` (for SQLite) or `psycopg2` (for PostgreSQL). `psycopg` references the experimental psycopg3 driver, which may be used as a drop in replacement for `psycopg2`. If no name is specified Synapse will default to SQLite. Defaults to `"sqlite3"`.

* `txn_limit` (integer): Gives the maximum number of transactions to run per connection before reconnecting. 0 means no limit. Defaults to `0`.

Expand Down
Loading
Loading