MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _accept_in_hot_standby

Function _accept_in_hot_standby

asyncpg/connect_utils.py:1150–1168  ·  view source on GitHub ↗

If the server didn't report "in_hot_standby" at startup, we must determine the state by checking "SELECT pg_catalog.pg_is_in_recovery()". If the server allows a connection and states it is in recovery it must be a replica/standby server.

(should_be_in_hot_standby: bool)

Source from the content-addressed store, hash-verified

1148
1149
1150def _accept_in_hot_standby(should_be_in_hot_standby: bool):
1151 """
1152 If the server didn't report "in_hot_standby" at startup, we must determine
1153 the state by checking "SELECT pg_catalog.pg_is_in_recovery()".
1154 If the server allows a connection and states it is in recovery it must
1155 be a replica/standby server.
1156 """
1157 async def can_be_used(connection):
1158 settings = connection.get_settings()
1159 hot_standby_status = getattr(settings, 'in_hot_standby', None)
1160 if hot_standby_status is not None:
1161 is_in_hot_standby = hot_standby_status == 'on'
1162 else:
1163 is_in_hot_standby = await connection.fetchval(
1164 "SELECT pg_catalog.pg_is_in_recovery()"
1165 )
1166 return is_in_hot_standby == should_be_in_hot_standby
1167
1168 return can_be_used
1169
1170
1171def _accept_read_only(should_be_read_only: bool):

Callers 2

can_be_usedFunction · 0.85
connect_utils.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…