Reputation: 1892
I'm trying to use the pg_dump tool on my local machine. However, when I type pg_dump database_name
into my terminal window, I get the message that states:
pg_dump: [archiver (db)] connection to database "demo" failed:
could not connect to server: No such file or directory
After receiving this error message, I went into my postgressql.conf file (the configuration file for postgres) and set the listen_addresses to *
. My connection strings appear below:
- Connection Settings -
#listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
max_connections = 20 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directory = '' # (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
I then rebooted my machine, hoping that when I type in pg_dump
in the console, something different would happen. However, even after a restart, I'm still getting the could not connect to server error message (as I have described above).
What steps should I try next in order to remedy this issue?
Thank you in advance
Upvotes: 1
Views: 7396
Reputation: 324265
You're on Mac OS X, right?
Your PATH is wrong, it's finding psql
, pg_dump
, etc from Apple's built-in copy of psql
PostgreSQL, not the one you installed separately.
Try using -h /tmp
or -h localhost
. If that works, that confirms this is the problem. To fix it properly you need to adjust your PATH
so that the correct PostgreSQL binaries are there first.
(I'm quite annoyed at Apple for bundling PostgreSQL in OS X with the tools on the default system PATH and clashing with any user-installed ones).
Your follow-up comment confirms that this is the problem. You need to run the pg_dump
from the version of PostgreSQL you installed. Since you didn't say how you installed PostgreSQL, your operating system, or anything else I suggest that you do that by searching for the existing mentions of this problem. A search for something like:
"OS X" postgresql path
will be informative. So will this Stack Overflow search.
Alternately, you may explicitly give the path to pg_dump
. Where it is depends on how you installed PostgreSQL, which you did not mention. It could be /usr/local/bin/pg_dump
, /opt/
, etc.
Upvotes: 6