Re: pg_restore to a port where nobody is listening?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Daniel Westermann <daniel(dot)westermann(at)dbi-services(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: pg_restore to a port where nobody is listening?
Date: 2016-12-21 17:32:57
Message-ID: 18ca9130-23a5-7892-32a9-f50d356bf907@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/21/2016 09:22 AM, Daniel Westermann wrote:
> Hi all,
>
> I have a PostgreSQL 9.5.4 and a PostgreSQL 9.6.1 instance installed on
> the same host. I dump the 9.5.4 instance with:
>
> pg_dump -h localhost -p 5438 -C -c -F d -j 2 -f /var/tmp/exp/ test
>
> .. which runs fine. I get the output as expected:
> postgres(at)pgbox:/home/postgres/ [PG954] ls /var/tmp/exp/
> 3016.dat.gz 3017.dat.gz toc.dat
>
> Source instance:
> (postgres(at)[local]:5438) [postgres] > show port;
> port
> ------
> 5438
> (1 row)
>
> Time: 0.328 ms
> (postgres(at)[local]:5438) [postgres] > select version();
> -[ RECORD 1
> ]-----------------------------------------------------------------------------------------------------------------------
> version | PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC)
> 4.8.5 20150623 (Red Hat 4.8.5-4), 64-bit
>
> Now I try to import into 9.6.1 => the instance is not running but the
> environment is set:
>
> postgres(at)pgbox:/home/postgres/ [PG961] netstat -na | grep 5439
> postgres(at)pgbox:/home/postgres/ [PG961] echo $PGPORT
> 5439
>
> postgres(at)pgbox:/home/postgres/ [PG961] pg_restore -V
> pg_restore (PostgreSQL) 9.6.1
> postgres(at)pgbox:/home/postgres/ [PG961] pg_restore -h localhost -p 5439
> -F d -C -j 2 /var/tmp/exp/
>
> This runs fine but where does it connect to? Nothing is listening on
> port 5439.

https://www.postgresql.org/docs/9.5/static/app-pgrestore.html

"pg_restore can operate in two modes. If a database name is specified,
pg_restore connects to that database and restores archive contents
directly into the database. Otherwise, a script containing the SQL
commands necessary to rebuild the database is created and written to a
file or standard output. This script output is equivalent to the plain
text output format of pg_dump. Some of the options controlling the
output are therefore analogous to pg_dump options."

So you can use pg_restore to restore all or part of a pg_dump (custom
format) file to another file. I find this very handy.

>
> postgres(at)pgbox:/home/postgres/ [PG961] netstat -tulpen
> (Not all processes could be identified, non-owned process info
> will not be shown, you would have to be root to see it all.)
> Active Internet connections (only servers)
> Proto Recv-Q Send-Q Local Address Foreign Address
> State User Inode PID/Program name
> tcp 0 0 0.0.0.0:22 0.0.0.0:*
> LISTEN 0 15929 -
> tcp 0 0 127.0.0.1:25 0.0.0.0:*
> LISTEN 0 17460 -
> tcp 0 0 0.0.0.0:5438 0.0.0.0:*
> LISTEN 1000 18923 2829/postgres
> tcp6 0 0 :::22 :::*
> LISTEN 0 15938 -
> tcp6 0 0 ::1:25 :::*
> LISTEN 0 17461 -
> tcp6 0 0 :::5438 :::*
> LISTEN 1000 18924 2829/postgres
> udp 0 0 0.0.0.0:68
> 0.0.0.0:* 0 14940
> -
> udp 0 0 0.0.0.0:49566
> 0.0.0.0:* 0 14929
> -
> udp6 0 0 :::40307
> :::* 0 14930
> -
>
> postgres(at)pgbox:/home/postgres/ [PG961] psql -h localhost -p 5439
> psql: could not connect to server: Connection refused
> Is the server running on host "localhost" (::1) and accepting
> TCP/IP connections on port 5439?
> could not connect to server: Connection refused
> Is the server running on host "localhost" (127.0.0.1) and accepting
> TCP/IP connections on port 5439?
>
> What do I miss? I can give any port to pg_restore and it just seems to
> be fine. Even this seems to working (the copy from stdin is displayed on
> the screen):
> postgres(at)pgbox:/home/postgres/ [PG961] pg_restore -h localhost -p
> ===6666 -F d -C /var/tmp/exp/
>
>
> Thanks
> Daniel
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2016-12-21 17:38:04 Re: pg_restore to a port where nobody is listening?
Previous Message Daniel Westermann 2016-12-21 17:22:23 pg_restore to a port where nobody is listening?