See this part of the pg_dump
manpage:
-W, --password
Force pg_dump to prompt for a password before connecting to a database.
This option is never essential, since pg_dump will automatically prompt
for a password if the server demands password authentication.
Don't use -W
at all. In your case, it's just confusing.
Also, you need to know that the fact that the server asks for a password or not is not driven by the existence of this password.
It's driven by the server-side pg_hba.conf
file that you need to study and possibly modify according to your needs (don't forget to reload the server after modifying it).
EDIT: reviewing your pg_hba.conf. The relevant lines are:
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
The 1st line concerns the postgres
user. It's irrelevant for your pg_dump command since you're using the santa
user with -U santa
The 2nd line concerns any other connection through Unix domain sockets (TYPE column is local
). From the client, it means when you do not use -h localhost
. It says that if the OS user is the same name than the db user, he doesn't need a password.
The 3rd line says that if -h localhost
is used (IPv4 TCP connection), a password will always be asked to the client. The 4th line says the same with IPv6.
Based on this, this command run by the santa
OS user should not ask or need a password:
pg_dump --no-owner myapp_db > myapp_db_backup.sql
-U santa
is optional because the db username is taken as the OS user by default.
Superusers are always exempt from lowly permission checks. The documentation:
superuser status
A database superuser bypasses all permission checks, except the right
to log in. This is a dangerous privilege and should not be used carelessly; ...
To see whether your current user is a superuser:
SHOW IS_SUPERUSER;
To list all superuser roles:
SELECT rolname FROM pg_roles WHERE rolsuper;
And the schema owner can do it, too. The documentation for DROP TABLE
:
Only the table owner, the schema owner, and superuser can drop a table.
To list schema-owners:
SELECT n.nspname AS schema_name, pg_get_userbyid(n.nspowner) AS owner
FROM pg_namespace n
WHERE n.nspname NOT LIKE 'pg_%'
AND n.nspname <> 'information_schema'
ORDER BY 1;
About the same as \dn
in psql.
And who are you?
SELECT current_user, session_user;
Best Answer
You probably created some tables (with data) in the database
template1
.Connect to that database (e.g.:
psql postgres template1
) and drop everything you don't need there.More details in the manual: http://www.postgresql.org/docs/current/static/manage-ag-templatedbs.html