execute ( sql, ( date, date )) result = In the following application code snippet, written in Python and edited so that you can see all the interesting bits in a very short amount of code, you can see that you connect to a Postgres service (here using the psycopg2 driver) and then use the connection to execute a query:ĬONNSTRING = "dbname=yesql application_name=app host=node1" def fetch_month_data ( year, month ): "Fetch a month of data from the database" date = "%d-%02d-01" % ( year, month ) sql = """ How Connection Strings work with Postgres When a failover happens, all this state is lost. The PostgreSQL connection support specific connection-time properties and GUCs (Postgres settings are called GUC variables.) Then a connection hosts a session, and Postgres exposes session-level objects such as temporary tables, server-side prepared-statements, cursors, and even more. What’s true of all those different deployment options though is that a PostgreSQL connection is stateful. Your application will get an error when trying to use the previously established connection, without any way to anticipate the situation. The most important thing to know about client-side HA is that when a failover happens, the connections to Postgres are lost. But it’s still useful to understand what happens to your application when a Postgres failover occurs. Now, if you’re running your app on top of a managed service with HA, you probably don’t need to worry about how to implement HA, as HA is managed by the service. Your application might be running on Postgres on-prem with HA configured-or in the cloud-or on a managed PostgreSQL service such as Azure Database for PostgreSQL. In this post, you will learn what happens to your application code and connections when a Postgres failover is orchestrated. Application code has a super important role to play, too. That said, the server side of the stack is not the only thing that matters when implementing high availability. Having a Postgres service running with the expected data set is all-important and required for HA, of course. When those of us who work on Postgres High Availability explain how HA in Postgres works, we often focus on the server side of the stack.
0 Comments
Leave a Reply. |