Postgresql - pg_dump - no matching schemas were found
Asked Answered
B

6

6

I'm trying to create a backup from PostgreSQL database, but getting the following error: pg_dump: No matching schemas were found

I'm logged in as root and running the command

pg_dump -f db.dump --format=plain --schema=existing_schema --username=userx --host=localhost databasename

  1. I logged in with userx to psql and tried \dt - this gave me information, that schema with name existing_schema is public.
  2. I checked \l to see that databasename is the database name.
  3. Password is correct, otherwise I could not access psql.
  4. Localhost is correct, checked from running processes. Tried the ip-address of the server also, but in this case pg_admin gave an error about the host address.

Output of \dl:

 
                  List of relations

Schema |                Name                 | Type  | Owner
--------+-------------------------------------+-------+-------
 public | existing_schema                    | table | userx
Betweenwhiles answered 26/9, 2012 at 10:18 Comment(6)
"schema with name existing_schema is public" that doesn't make sense. Is that schema schema named public or is it named existing_schema?Pepys
That means, that if I enter the command \dt, I'll get the result: Schema | Name | Type | Owner ::: public | existing_schema | table | userxBetweenwhiles
"Owner public" is not something the \dt command would display.Pepys
It displays Schema : public | Name : existing_schema | Type : table | Owner : userx. Schema, Name, Type and Owner are column headers and public, existing_schema, table, userx are column values in one row. Tried to put them under eachother, but didn't work in comment, sorry.Betweenwhiles
Can you add the output (copy & paste) to your question? (enclose it in <pre> tags)Pepys
Why are you running these as root and not as postgres?Euripus
P
6

The schema's name is public.

existing_schema is the name of a table in the schema public.

It's not clear from your pg_dump commandline what you want to do.

If you want to export all tables from the schema public you need to specify:

--schema=public

If you want to export only the table existing_schema then you need to specify:

--table=existing_schema
Pepys answered 26/9, 2012 at 10:55 Comment(0)
I
14

You can try with back slash and double quote as metioned here.

sudo -u postgres pg_dump -v Database_Name -t "\"Table_Name\""
Immunotherapy answered 24/8, 2015 at 5:35 Comment(0)
P
6

The schema's name is public.

existing_schema is the name of a table in the schema public.

It's not clear from your pg_dump commandline what you want to do.

If you want to export all tables from the schema public you need to specify:

--schema=public

If you want to export only the table existing_schema then you need to specify:

--table=existing_schema
Pepys answered 26/9, 2012 at 10:55 Comment(0)
L
6

For future googlers, in my case my schema had dots ("my.schema"), and the proper way to address this is by escaping:

pg_dump -U postgres -d mydatabase --schema \"my.schema\"
Lasseter answered 7/2, 2019 at 11:52 Comment(1)
This also works for specified tables. The usual advice is to use: --table=blah but to escape tables (e.g. when the name includes capitals) you can use: --table \"tableName\"Dissuasion
M
0
      \dn list out all the schema in the database 

if you want to dump only schema ,

refer

Mindimindless answered 26/9, 2012 at 11:9 Comment(0)
S
0

In my case the schema name was upper case and no matter what I tried (-n MYSCHEMA, -n "MYSCHEMA", -n "\"MYSCHEMA\"") it did not work until I renamed the schema to "myschema" in the database. Then I could dump with all of -n MYSCHEMA, -n "MYSCHEMA", and -n "\"MYSCHEMA\"".

It looks like pg_dump internally uses lower case, that means it doesn't quote the schema name given in the command line.

However when calling pg_dump with -n """MYSCHEMA""" it works.

When adding a table name however the option -n did not work anymore for me. If schema and table-name contains capitalized letters, I used this:

pg_dump -f file.txt -t \"MySchema\".\"MyTable\".

Skeg answered 27/1, 2021 at 12:3 Comment(0)
M
0

this worked for me --schema "\"your_schema\""

Muller answered 14/11, 2023 at 22:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.