bashpg-dump

How to resolve a pg_dump Error From bash Script


I have a bash script which results in an unanticipated result, which may/may not be DNS. Honestly, I'm not sure. Hopefully, the expert knowledge base here can lead me in the correct direction! I'm doubtful if it's a version mismatch between pg_dump and postgres.

DISCLAIMERS:

Sorry for all the disclaimers, trying to minimize some questions.

Using:

Here's the script:

servera=<serverA_address>
serverb=<serverB_address>
serverc=<serverC_address>
serverd=<serverD_address>
port=5432
database=postgres
user=<user_name>
PGPASSWORD=<password>
dtg=$(date "+%Y-%m-%d")
export PGPASSWORD
pg_dump -U ${user} -h ${servera} -p ${port} -d ${database} -F t > ${dtg}_serverAdump.tar
pg_dump -U ${user} -h ${serverb} -p ${port} -d ${database} -F t > ${dtg}_serverBdump.tar
pg_dump -U ${user} -h ${serverc} -p ${port} -d ${database} -F t > ${dtg}_serverCdump.tar
pg_dump -U ${user} -h ${serverd} -p ${port} -d ${database} -F t > ${dtg}_serverDdump.tar

Here's the output from the terminal:

    pg_dump: error: could not translate host name "<serverA_address>" to address: Name or service not known
    pg_dump: error: could not translate host name "<serverB_address>" to address: Name or service not known
    pg_dump: error: could not translate host name "<serverC_address>" to address: Name or service not known
    pg_dump: error: could not translate host name "<serverD_address>" to address: Name or service not known

If I run the pg_dump command via CLI, it works. Here is output from nslookup,

nslookup <serverA_address>
Server:     a.b.c.d
Address:    a.b.c.d#<port>
Non-authoritative answer:
Name:   <serverA_address>
Address:    a.b.c.d

Here is output from dig:

    ; <<>> Dig 9.16.23-RH <serverA_address>
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48340
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 1232
    ; COOKIE <cookie_value> (good)
    ;; QUESTION SECTION:; <serverA_address>. IN A
    ;; ANSWER SECTION: <serverA_address>. 5 IN A <serverA_ip_address>
    ;; Query time: 7 msec
    ;; SERVER: <serverA_ip_address>#<port>
(<serverA_ip_address>)
    ;; WHEN: Wed Jun 18 <etc>
    ;; MSG SIZE  rcvd: 138

Google searching the "pg_dump: error ..." did yield the following (and others), but nothing that seems to help. psql: could not translate host name "somePostgres" to address: Name or service not known


Solution

  • Everyone -

    Here's what I've done, and it seems to have worked.

    Took the "meat" of the script (i.e. that which was posted), created a brand new file, then ran the script. Success. I don't know why, other than somehow/maybe, non-visible characters were included in original, and now are no longer exist.

    Appreciate everyone who tried. Thanks!