
{"id":6104,"date":"2024-09-25T07:51:23","date_gmt":"2024-09-25T07:51:23","guid":{"rendered":"https:\/\/test.opensource-db.in\/wp1\/?p=6104"},"modified":"2024-09-25T09:51:05","modified_gmt":"2024-09-25T09:51:05","slug":"postgresql-connection-failover-and-load-balancing-with-libpq","status":"publish","type":"post","link":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/","title":{"rendered":"PostgreSQL Connection Failover and Load Balancing with libpq"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As database administrators, our primary goal is to ensure data redundancy. One popular method to achieve this is replication failover. Regardless of the number of primary and standby nodes within a data centre (DC) and disaster recovery (DR) setup, if the database is not accessible to the application, the failover mechanism is not useful for the business.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Understanding <code>libpq<\/code>:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Libpq is a client library written in C that facilitates communication between applications and PostgreSQL databases. It is widely used in developing software that interacts with PostgreSQL. Popular tools like pgbench and psql utilize libpq for communication with PostgreSQL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Features of <code>libpq<\/code><\/strong>:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL offers a unique client access library called <code>libpq<\/code>, which provides a failover mechanism for client applications with multiple host connections simultaneously. It includes attribute options like <code>read-write<\/code> and <code>any<\/code> to handle both primary and standby servers. In PostgreSQL 16, load balancing was introduced directly from the application connection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Use cases with <code>libpq<\/code><\/strong>:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When the primary node is alive, the application connects to the primary. When it is down, the replication configuration automatically upgrades one of the standbys to primary. Here, the connection string and\/or IP address could be different &#8211; unless you&#8217;re using a HAProxy or a VIP. In this scenario, the <code>libpq<\/code> library will automatically detect which database node is primary and connect to that host from the given pool of hosts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Connection Mechanism<\/strong>:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s important to note that the driver may take extra time to connect to each node in the list to determine if it is the master. For instance, if the server at <code>192.168.226.128<\/code> is no longer the master, and <code>192.168.226.129<\/code> (the second server in the connection string) has become the new master accepting writes, the driver will first check if the initial server allows writes. If the first server is unreachable, the driver will then attempt to connect to the second one. This may introduce additional delay, but the failover remains seamless, ensuring that the application does not need to be interrupted during the switchover.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Practical Example<\/strong>:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To better understand this, let&#8217;s look at a simple scenario. I have set up a three-node replication cluster:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>192.168.226.128 &#8211; Master<\/li>\n\n\n\n<li>192.168.226.129 &#8211; First Standby<\/li>\n\n\n\n<li>192.168.226.130 &#8211; Second Standby<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Connecting to the Master Using Read-Write Mode<\/strong>:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how to achieve this using Python. I&#8217;ve written a simple Python script where I set target_session_attrs to &#8220;read-write&#8221; and provided multiple IPs for the host. When I run the script, it verifies the connected IP (in this case, 192.168.226.128 as the master) and confirms that the server is not in recovery mode.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def init_db_connection():\n    conn = psycopg2.connect(\n        database=\"postgres\",\n        host=\"192.168.226.129,192.168.226.128,192.168.226.130\",\n        user=\"postgres\",\n        password=\"secret\",\n        port=\"5432\",\n        target_session_attrs=\"read-write\",\n        load_balance_hosts=\"random\"\n    )\n    return conn\n\n@app.route('\/status')\ndef check_status():\n    conn = init_db_connection()\n    cur = conn.cursor()\n    cur.execute(\"SELECT pg_is_in_recovery(), inet_server_addr()\")\n    status = cur.fetchone()\n    cur.close()\n    conn.close()\n    return f\"Server in recovery: {status&#091;0]}, IP address: {status&#091;1]}\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above \/status route connects to the primary server. You can see this in the browser:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Server in recovery: False, IP address: 192.168.226.128<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the primary server changes, the application will automatically connect to the new primary IP address.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Connecting to Any Server for Reads<\/strong>:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For select queries, we can leverage the load balancing feature of <code>libpq<\/code>. With the <code>load_balance_hosts<\/code> option, the IPs are shuffled every time a connection is established, so a random host will connect to the application server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def get_db_connection():\n    conn = psycopg2.connect(\n        database=\"postgres\",\n        host=\"192.168.226.129,192.168.226.128,192.168.226.130\",\n        user=\"postgres\",\n        password=\"secret\",\n        port=\"5432\",\n        target_session_attrs=\"any\",\n        load_balance_hosts=\"random\"\n    )\n    return conn\n\n@app.route('\/')\ndef index():\n    conn = get_db_connection()\n    cur = conn.cursor()\n    # Execute the query to get recovery status and server IP address\n    cur.execute(\"SELECT pg_is_in_recovery(), inet_server_addr()\")\n    result = cur.fetchone()  # Fetch the result (a single row)\n    # `result` is a tuple, where result&#091;0] is the recovery status, and result&#091;1] is the server IP address\n    recovery_status, ip_address = result\n    print(f\"SELECT: Connected to database on IP: {ip_address}, Recovery status: {recovery_status}\")\n    # Fetch items data\n    cur.execute('SELECT * FROM items')\n    items = cur.fetchall()\n    cur.close()\n    conn.close()\n    return render_template('index.html', items=items)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example output:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT: Connected to database on IP: 192.168.226.128, Recovery status: False\n127.0.0.1 - - &#091;25\/Sep\/2024 07:38:27] \"GET \/ HTTP\/1.1\" 200 -\nSELECT: Connected to database on IP: 192.168.226.129, Recovery status: False\n127.0.0.1 - - &#091;25\/Sep\/2024 07:38:27] \"GET \/ HTTP\/1.1\" 200 -\nSELECT: Connected to database on IP: 192.168.226.129, Recovery status: False\n127.0.0.1 - - &#091;25\/Sep\/2024 07:38:35] \"GET \/ HTTP\/1.1\" 200 -\nSELECT: Connected to database on IP: 192.168.226.129, Recovery status: False\n127.0.0.1 - - &#091;25\/Sep\/2024 07:38:35] \"GET \/ HTTP\/1.1\" 200 -\nSELECT: Connected to database on IP: 192.168.226.129, Recovery status: False\n127.0.0.1 - - &#091;25\/Sep\/2024 07:38:35] \"GET \/ HTTP\/1.1\" 200 -\nSELECT: Connected to database on IP: 192.168.226.131, Recovery status: False\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL&#8217;s <code>libpq<\/code> library offers a robust solution for seamless database failover and load balancing. By leveraging its features, such as multiple host connections, read-write attributes, and load balancing, application developers can ensure high availability and reliability of their connections to PostgreSQL databases. This not only minimizes downtime but also enhances the overall performance and resilience of the application. Implementing <code>libpq<\/code> in your setup can significantly improve the accessibility and efficiency of your database operations, making it a valuable tool for any organization relying on PostgreSQL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: As database administrators, our primary goal is to ensure data redundancy. One popular method to achieve this is replication [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":6114,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1,23],"tags":[],"class_list":["post-6104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-others","category-postgresql-14"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PostgreSQL Connection Failover and Load Balancing with libpq - OpenSource DB<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL Connection Failover and Load Balancing with libpq - OpenSource DB\" \/>\n<meta property=\"og:description\" content=\"Introduction: As database administrators, our primary goal is to ensure data redundancy. One popular method to achieve this is replication [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/\" \/>\n<meta property=\"og:site_name\" content=\"OpenSource DB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-25T07:51:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-25T09:51:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"945\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shashidhar Reddy Dakuri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@opensource_db\" \/>\n<meta name=\"twitter:site\" content=\"@opensource_db\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shashidhar Reddy Dakuri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/\"},\"author\":{\"name\":\"Shashidhar Reddy Dakuri\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/633b2c7eaee7834752cb1e4e00834394\"},\"headline\":\"PostgreSQL Connection Failover and Load Balancing with libpq\",\"datePublished\":\"2024-09-25T07:51:23+00:00\",\"dateModified\":\"2024-09-25T09:51:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/\"},\"wordCount\":588,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#organization\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png\",\"articleSection\":[\"Others\",\"PostgreSQL 14\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/\",\"name\":\"PostgreSQL Connection Failover and Load Balancing with libpq - OpenSource DB\",\"isPartOf\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png\",\"datePublished\":\"2024-09-25T07:51:23+00:00\",\"dateModified\":\"2024-09-25T09:51:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png\",\"contentUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png\",\"width\":1800,\"height\":945},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/test.opensource-db.in\/wp1\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Connection Failover and Load Balancing with libpq\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#website\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/\",\"name\":\"OpenSource DB\",\"description\":\"Your Trusted OpenSource Databases partner\",\"publisher\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/test.opensource-db.in\/wp1\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#organization\",\"name\":\"OPENSOURCE DB PRIVATE LIMITED\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png\",\"contentUrl\":\"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png\",\"width\":368,\"height\":120,\"caption\":\"OPENSOURCE DB PRIVATE LIMITED\"},\"image\":{\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/\",\"https:\/\/x.com\/opensource_db\",\"https:\/\/www.youtube.com\/channel\/UCmTI5h\",\"https:\/\/www.linkedin.com\/company\/opensource-db\",\"https:\/\/www.instagram.com\/opensource_db\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/633b2c7eaee7834752cb1e4e00834394\",\"name\":\"Shashidhar Reddy Dakuri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/76c7e2f443cd53fe7d76279cbd4dd4db8a098d8bc0e5fe7f69f785cc67654e71?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/76c7e2f443cd53fe7d76279cbd4dd4db8a098d8bc0e5fe7f69f785cc67654e71?s=96&d=mm&r=g\",\"caption\":\"Shashidhar Reddy Dakuri\"},\"url\":\"https:\/\/test.opensource-db.in\/wp1\/author\/shashidhar-reddy\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL Connection Failover and Load Balancing with libpq - OpenSource DB","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"PostgreSQL Connection Failover and Load Balancing with libpq - OpenSource DB","og_description":"Introduction: As database administrators, our primary goal is to ensure data redundancy. One popular method to achieve this is replication [&hellip;]","og_url":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/","og_site_name":"OpenSource DB","article_publisher":"https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/","article_published_time":"2024-09-25T07:51:23+00:00","article_modified_time":"2024-09-25T09:51:05+00:00","og_image":[{"width":1800,"height":945,"url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png","type":"image\/png"}],"author":"Shashidhar Reddy Dakuri","twitter_card":"summary_large_image","twitter_creator":"@opensource_db","twitter_site":"@opensource_db","twitter_misc":{"Written by":"Shashidhar Reddy Dakuri","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#article","isPartOf":{"@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/"},"author":{"name":"Shashidhar Reddy Dakuri","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/633b2c7eaee7834752cb1e4e00834394"},"headline":"PostgreSQL Connection Failover and Load Balancing with libpq","datePublished":"2024-09-25T07:51:23+00:00","dateModified":"2024-09-25T09:51:05+00:00","mainEntityOfPage":{"@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/"},"wordCount":588,"commentCount":0,"publisher":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#organization"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage"},"thumbnailUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png","articleSection":["Others","PostgreSQL 14"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/","url":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/","name":"PostgreSQL Connection Failover and Load Balancing with libpq - OpenSource DB","isPartOf":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#website"},"primaryImageOfPage":{"@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage"},"thumbnailUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png","datePublished":"2024-09-25T07:51:23+00:00","dateModified":"2024-09-25T09:51:05+00:00","breadcrumb":{"@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#primaryimage","url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png","contentUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png","width":1800,"height":945},{"@type":"BreadcrumbList","@id":"https:\/\/test.opensource-db.in\/wp1\/postgresql-connection-failover-and-load-balancing-with-libpq\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/test.opensource-db.in\/wp1\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Connection Failover and Load Balancing with libpq"}]},{"@type":"WebSite","@id":"https:\/\/test.opensource-db.in\/wp1\/#website","url":"https:\/\/test.opensource-db.in\/wp1\/","name":"OpenSource DB","description":"Your Trusted OpenSource Databases partner","publisher":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/test.opensource-db.in\/wp1\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/test.opensource-db.in\/wp1\/#organization","name":"OPENSOURCE DB PRIVATE LIMITED","url":"https:\/\/test.opensource-db.in\/wp1\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/","url":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png","contentUrl":"https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2021\/10\/osdb-logo-tm-2.png","width":368,"height":120,"caption":"OPENSOURCE DB PRIVATE LIMITED"},"image":{"@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/people\/OpenSource-DB\/100072970755470\/","https:\/\/x.com\/opensource_db","https:\/\/www.youtube.com\/channel\/UCmTI5h","https:\/\/www.linkedin.com\/company\/opensource-db","https:\/\/www.instagram.com\/opensource_db\/"]},{"@type":"Person","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/633b2c7eaee7834752cb1e4e00834394","name":"Shashidhar Reddy Dakuri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/test.opensource-db.in\/wp1\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/76c7e2f443cd53fe7d76279cbd4dd4db8a098d8bc0e5fe7f69f785cc67654e71?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/76c7e2f443cd53fe7d76279cbd4dd4db8a098d8bc0e5fe7f69f785cc67654e71?s=96&d=mm&r=g","caption":"Shashidhar Reddy Dakuri"},"url":"https:\/\/test.opensource-db.in\/wp1\/author\/shashidhar-reddy\/"}]}},"rttpg_featured_image_url":{"full":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",1800,945,false],"landscape":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",1800,945,false],"portraits":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",1800,945,false],"thumbnail":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1-150x150.png",150,150,true],"medium":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1-300x158.png",300,158,true],"large":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1-1024x538.png",1024,538,true],"1536x1536":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1-1536x806.png",1536,806,true],"2048x2048":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",1800,945,false],"ultp_layout_landscape_large":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",1200,630,false],"ultp_layout_landscape":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",870,457,false],"ultp_layout_portrait":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",600,315,false],"ultp_layout_square":["https:\/\/test.opensource-db.in\/wp1\/wp-content\/uploads\/2024\/09\/image-8-1.png",600,315,false]},"rttpg_author":{"display_name":"Shashidhar Reddy Dakuri","author_link":"https:\/\/test.opensource-db.in\/wp1\/author\/shashidhar-reddy\/"},"rttpg_comment":0,"rttpg_category":"<a href=\"https:\/\/test.opensource-db.in\/wp1\/category\/business\/others\/\" rel=\"category tag\">Others<\/a> <a href=\"https:\/\/test.opensource-db.in\/wp1\/category\/postgres\/postgresql-14\/\" rel=\"category tag\">PostgreSQL 14<\/a>","rttpg_excerpt":"Introduction: As database administrators, our primary goal is to ensure data redundancy. One popular method to achieve this is replication [&hellip;]","_links":{"self":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/6104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/comments?post=6104"}],"version-history":[{"count":4,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/6104\/revisions"}],"predecessor-version":[{"id":6112,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/posts\/6104\/revisions\/6112"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/media\/6114"}],"wp:attachment":[{"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/media?parent=6104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/categories?post=6104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.opensource-db.in\/wp1\/wp-json\/wp\/v2\/tags?post=6104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}