Skip to content

Commit e3934fd

Browse files
committed
Postgres 9.2 compatibility: propid got renamed to pid
1 parent 93a82f8 commit e3934fd

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

postgresql/driver/pq3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,8 @@ def _establish(self):
24942494
vi = self.version_info[:2]
24952495
if vi <= (8,1):
24962496
sd = self.sys.startup_data_only_version()
2497+
elif vi >= (9,2):
2498+
sd = self.sys.startup_data_92()
24972499
else:
24982500
sd = self.sys.startup_data()
24992501
# connection info

postgresql/lib/libsys.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ UNION ALL SELECT
173173
NULL::int AS client_port
174174
LIMIT 1;
175175

176+
[startup_data_92:transient:first]
177+
-- 9.2 and greater
178+
SELECT
179+
pg_catalog.version()::text AS version,
180+
backend_start::text,
181+
client_addr::text,
182+
client_port::int
183+
FROM pg_catalog.pg_stat_activity WHERE pid = pg_catalog.pg_backend_pid()
184+
UNION ALL SELECT
185+
pg_catalog.version()::text AS version,
186+
NULL::text AS backend_start,
187+
NULL::text AS client_addr,
188+
NULL::int AS client_port
189+
LIMIT 1;
190+
176191
[startup_data_no_start:transient:first]
177192
-- 8.1 only, but is unused as often the backend's activity row is not
178193
-- immediately present.
@@ -200,6 +215,15 @@ FROM
200215
WHERE
201216
procpid != pg_catalog.pg_backend_pid()
202217

218+
[terminate_backends_92:transient:column]
219+
-- Terminate all except mine. 9.2 and later
220+
SELECT
221+
pid, pg_catalog.pg_terminate_backend(pid)
222+
FROM
223+
pg_catalog.pg_stat_activity
224+
WHERE
225+
pid != pg_catalog.pg_backend_pid()
226+
203227
[cancel_backends:transient:column]
204228
-- Cancel all except mine.
205229
SELECT
@@ -209,6 +233,15 @@ FROM
209233
WHERE
210234
procpid != pg_catalog.pg_backend_pid()
211235

236+
[cancel_backends_92:transient:column]
237+
-- Cancel all except mine. 9.2 and later
238+
SELECT
239+
pid, pg_catalog.pg_cancel_backend(pid)
240+
FROM
241+
pg_catalog.pg_stat_activity
242+
WHERE
243+
pid != pg_catalog.pg_backend_pid()
244+
212245
[sizeof_db:transient:first]
213246
SELECT pg_catalog.pg_database_size(current_database())::bigint
214247

postgresql/temporal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ def destroy(self):
6565
try:
6666
c = cluster.connection(user = 'test', database = 'template1',)
6767
with c:
68-
c.sys.terminate_backends()
68+
if c.version_info[:2] <= (9,1):
69+
c.sys.terminate_backends()
70+
else:
71+
c.sys.terminate_backends_92()
6972
except Exception:
7073
# Doesn't matter much if it fails.
7174
pass

postgresql/test/test_driver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,10 @@ def testBadFD(self):
17421742
@pg_tmp
17431743
def testAdminTerminated(self):
17441744
with new() as killer:
1745-
killer.sys.terminate_backends()
1745+
if killer.version_info[:2] <= (9,1):
1746+
killer.sys.terminate_backends()
1747+
else:
1748+
killer.sys.terminate_backends_92()
17461749

17471750
self.assertRaises(
17481751
pg_exc.AdminShutdownError,

0 commit comments

Comments
 (0)