{"id":16533,"date":"2021-07-13T12:18:19","date_gmt":"2021-07-13T10:18:19","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/"},"modified":"2024-11-08T15:15:00","modified_gmt":"2024-11-08T14:15:00","slug":"setup-pgpass-for-replication","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/","title":{"rendered":"Setup pgpass for replication"},"content":{"rendered":"<p>This script provides functionality to setup passwordless authentication in PostgreSQL for defined Server Names.<br \/>\nThis is very helpful by using replication via repmgr and is not Linux Distribution specific, it was used till now with SLES 12, SLES 15 and RHEL 8 Clones.<\/p>\n<p>As all of my scripts it provides help how the usage is with -h parameter:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n$ [[root@rocky ~]$ sh pgpass.sh -h\n$ [[root@rocky ~]$ Usage:\n$ [[root@rocky ~]$ pgpass.sh [OPTION]\n$ [[root@rocky ~]$ \n$ [[root@rocky ~]$ Options:\n$ [[root@rocky ~]$          -p                     server where the primary host is running on (required)\n$ [[root@rocky ~]$          -s                     server where the secondary host is running on (required)\n$ [[root@rocky ~]$          -h                     prints this help\n<\/pre>\n<p>The parameters -p and -s should be server DNS Names without domain, the domain will be specified within the script.<\/p>\n<p>The script itself:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n\n!\/bin\/sh\n\n########################################\n#  pgpass setup script                 #\n#  Author: Karsten Lenz \/ 2020.07.13   #\n########################################\n\nprogName=$(basename $0)\ndomain=put your domain here\npostgresHome=\/var\/lib\/pgsql\npgpass=$postgresHome\/.pgpass\npassword=put your password here\n\nfunction printHelp() {\n  printf \"Usage:n\"\n  printf \"${progName} [OPTION]nn\"\n  printf \"Options:n\"\n  printf \"t -p tttserver where the primary host is running on (required)n\"\n  printf \"t -s tttserver where the secondary host is running on (required)n\"\n  printf \"t -h ttttprints this helpn\"\n}\n\nwhile getopts p:s:h option 2&gt;\/dev\/null\ndo\n  case \"${option}\"\n  in\n  p) primServer=${OPTARG};;\n  s) secdServer=${OPTARG};;\n  h) printHelp; exit 2;;\n  *) printf \"Unsupported option or parameter value missing '$*'n\";\n     printf \"Run ${progName} -h to print helpn\"; exit 1;;\n  esac\ndone\n\n############ Log function ############\n\nlogFile=\/tmp\/pgpass_install.log\n\nfunction log() {\n  echo \"$(date +%Y.%m.%d-%H:%M:%S) [$$]$*\" | tee -a $logFile\n}\n\nif [ -f $logFile ]; then\n  continue\nelse\n  touch $logFile\n  chmod -R 774 $logFile\n  sleep 2\nfi\n\n#clean .pgpass\nrm -f $pgpass\n\n#set values in .pgpass\nlog \"INFO: #host:port:database:user:password in $pgpass\"\necho \"#host:port:database:user:password\" | tee -a $pgpass\nlog \"INFO: Setting localhost in $pgass\"\necho \"localhost:5432:*:repmgr:$password\" | tee -a $pgpass\nlog \"INFO: Setting 127.0.0.1 in $pgpass\"\necho \"127.0.0.1:5432:*:repmgr:$password\" | tee -a $pgpass\nlog \"INFO: Setting Primary $primServer in $pgpass\"\necho \"$primServer.$domain:5432:*:repmgr:$password\" | tee -a $pgpass\nlog \"INFO: Setting Primary $secdServer in $pgpass\"\necho \"$secdServer.$domain:5432:*:repmgr:$password\" | tee -a $pgpass\n\n#set .pgpass 0600\nchmod 0600 $pgpass\n\n<\/pre>\n<p>The script is used in a customer build cloud solution as part of recurrent setup step of replication using repmgr.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This script provides functionality to setup passwordless authentication in PostgreSQL for defined Server Names. This is very helpful by using replication via repmgr and is not Linux Distribution specific, it was used till now with SLES 12, SLES 15 and RHEL 8 Clones. As all of my scripts it provides help how the usage is [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[2602],"type_dbi":[],"class_list":["post-16533","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","tag-postgresql-2"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Setup pgpass for replication - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setup pgpass for replication\" \/>\n<meta property=\"og:description\" content=\"This script provides functionality to setup passwordless authentication in PostgreSQL for defined Server Names. This is very helpful by using replication via repmgr and is not Linux Distribution specific, it was used till now with SLES 12, SLES 15 and RHEL 8 Clones. As all of my scripts it provides help how the usage is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-13T10:18:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-08T14:15:00+00:00\" \/>\n<meta name=\"author\" content=\"Open source Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Open source Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/\"},\"author\":{\"name\":\"Open source Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\"},\"headline\":\"Setup pgpass for replication\",\"datePublished\":\"2021-07-13T10:18:19+00:00\",\"dateModified\":\"2024-11-08T14:15:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/\"},\"wordCount\":102,\"commentCount\":0,\"keywords\":[\"postgresql\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/\",\"name\":\"Setup pgpass for replication - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2021-07-13T10:18:19+00:00\",\"dateModified\":\"2024-11-08T14:15:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setup pgpass for replication\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\",\"name\":\"Open source Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"caption\":\"Open source Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Setup pgpass for replication - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/","og_locale":"en_US","og_type":"article","og_title":"Setup pgpass for replication","og_description":"This script provides functionality to setup passwordless authentication in PostgreSQL for defined Server Names. This is very helpful by using replication via repmgr and is not Linux Distribution specific, it was used till now with SLES 12, SLES 15 and RHEL 8 Clones. As all of my scripts it provides help how the usage is [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/","og_site_name":"dbi Blog","article_published_time":"2021-07-13T10:18:19+00:00","article_modified_time":"2024-11-08T14:15:00+00:00","author":"Open source Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Open source Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/"},"author":{"name":"Open source Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b"},"headline":"Setup pgpass for replication","datePublished":"2021-07-13T10:18:19+00:00","dateModified":"2024-11-08T14:15:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/"},"wordCount":102,"commentCount":0,"keywords":["postgresql"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/","url":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/","name":"Setup pgpass for replication - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2021-07-13T10:18:19+00:00","dateModified":"2024-11-08T14:15:00+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/setup-pgpass-for-replication\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Setup pgpass for replication"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b","name":"Open source Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","caption":"Open source Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/16533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=16533"}],"version-history":[{"count":1,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/16533\/revisions"}],"predecessor-version":[{"id":35665,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/16533\/revisions\/35665"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=16533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=16533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=16533"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=16533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}