3

Given the following Postgres container:

docker run -i -p 54350:5432 --name test_postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=test -e POSTGRES_SCHEMA=dba postgres:11 "-clog_statement=all" 

and the following init sql script:

CREATE SCHEMA IF NOT EXISTS dba; CREATE TABLE dba.mytable (mytable_id SERIAL); 

When running \dt in psql I get:

psql -U postgres -h localhost -p 54350 -d test test=# \dt dba.mytable List of relations Schema | Name | Type | Owner --------+---------------+-------+---------- dba | mytable | table | postgres (1 row) test=# 

But when I attempt to run pg_dump, I get the following:

pg_dump \ --username=postgres --host=localhost --port=54350 --dbname=test \ --schema-only \ --no-privileges \ --disable-triggers \ --no-publications \ --no-security-labels \ --no-subscriptions \ --no-synchronized-snapshots \ --quote-all-identifiers \ -t=dba.mytable > dump.sql Password: pg_dump: error: no matching tables were found 

I also tried with -t='"dba.mytable"' and -t="dba.mytable".

I also tried with -t=test.dba.mytable, -t='"test.dba.mytable"' and -t="test.dba.mytable", but then I get

pg_dump: error: cross-database references are not implemented: test.dba 

If I add --schema=dba I get:

pg_dump: error: no matching schemas were found 

Can you help me fix my pg_dump command so as to allow me to dump the table dba.mytable?

Thanks!

1 Answer 1

5

You are confused between long and short options. The documentation says:

-t pattern --table=pattern 

That means that pg_dump is looking for a table called =dba.mytable, which explains the error message. Use

pg_dump -t dba.mytable 

or

pg_dump --table=dba.mytable 
1
  • 1
    🙃 ... That solves it - thanks a lot Laurenz! Now I wish that the error printed would have been more verbose; that would have saved me a good hour and a half! Commented Mar 16, 2023 at 18:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.