Saving PostgreSQL database to an external HDD - postgresql

I need to save a database to an external HDD. This question has been asked previously here. However, upon changing the data_directory variable in the postgresql.conf file that exists in /usr/local/var/postgres/ to
data_directory = /path/to/externalHDD/directory/
I then restart the PostgreSQL server with brew services restart postgresql, but when I try to reconnect to the database via
psql -U username -d postgres
I receive the following error:
psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
How do I fix this?

If all you did was point data_directory somewhere else, that cannot work, because there is no data directory at the destination. You have to create the data directory using initdb.

Related

pqxx: broken_connection on trying to connect to posgres db

I have this problem trying to connect to the local postrgres databases. Until now i succeeded to connect to the same databases using jdbc or working directly in PGAdmin, this error happens when i try to connect using pqxx library or from shell:
pqxx code:
#include <pqxx/connection.hxx>
int main(){
pqxx::connection conn("user=postgres port=5432 dbname=pqxx-test password=postgres");
return 0;
}
or from shell, as user postgres:
psql pqxx-test
both the cases raise this error:
could not connect to server: No such file or directory Is the server
running locally and accepting connections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"
Searching for the solution i think i understood i have to edit pq_hba.conf and postgresql.conf files in order to connect in these ways, but in pg_hba.conf is already set:
local all all md5
and in postgresql.conf
listen_addresses='*'
And by the way, i'm not even able to edit these files because of a problem with the viminfo, but maybe this is another problem..
Can anyone help me?
edit:
using PostgreSQL 9.6.2
on Ubuntu 14.04
edit:
as postgres user, if i ask for the postgre version using:
psql -V
the result is 9.6.2
but looking at the file system hierarchy, all conf file are inside this folder
/opt/PostreSQL/9.4/data/
can that be the problem?
You seem to have a mix of client-side postgresql 9.6 configured for the ubuntu FS layout and a postgresql server 9.4 presumably downloaded from EntrepriseDB (and installed under /opt/PostgreSQL) using its own layout.
Assuming that the postgresql is running, the simplest solution is to add host=localhost to your connection string, so that it will use a TCP connection instead of the Unix domain socket /var/run/postgresql/.s.PGSQL.5432 that does not exist because of the mismatch.

GPDB-psql: could not connect to server: No such file or directory

We have the small array of Greenplum database.In that, We have a master node. when I am trying to use PSQL utility
Getting this error :
[gpadmin#master gpseg-1]$ psql
PSQL: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
We tried
on searching for postmaster.pid files.We have removed it.But still, the error remains.
You need to export your PGPORT and source Postgres.sh_path(inside your GPDB).
After that you will be able to do psql and connect to the database.

Unable to create user using postgres

I'm having a hard time getting postgres going for the first time. I installed pg with homebrew and I'm getting a error that looks pretty common on here:
createuser: could not connect to database postgres: could not connect
to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I've read that the most common solution is to remove the postmaster.pid file by running rm /usr/local/var/postgres/postmaster.pid
However, this results in the following:
rm: /usr/local/var/postgres/postmaster.pid: Permission denied
Any idea how I can get this going?

Problems trying to configure Ecrire with postgresql

I've been trying to configure Ecrire with my postgresql database, but I keep running into this error whenever I input psql -d postgres.
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I just don't know how to fix this. Please help!
Is the database running?
ps auxwf | grep postgres
It's also possible that the socket file is in another directory, or the database is listening on another port. Can you post the values "unix_socket_directories" and "port" from your postgresql.conf file?

postgres server started but could not connect to server

After I lost all the data on my computer (had to have everything erased by the Apple store), I installed postgres on my Mac using Homebrew with the command brew install postgres. I then started the server (with confirmation that the server was started) and tried to create a database for a Sinatra project that uses postgres, using the command
createdb db_development
However, I got the following error:
createdb: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
After searching online, I discovered that I might have to run the following initdb command
initdb /usr/local/var/postgres
but when I did it, I got this message
initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "braindead".
This user must also own the server process.
The database cluster will be initialized with locale "en_CA.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
So, why might postgres have confirmed the server had started at the same time I got this error could not connect to database postgres: could not connect to server: No such file or directory, and how could I fix this?
the READ.me for the project said
bundle install
createdb db_development
rake db:migrate
It either tries to connect to the postgres that comes with MacOS or PG environment variables are not set.
Try:
createdb -h localhost db_development
these are postgres environment variables for postgres. Also PostgresApp is a very convenient way to use Postgresql on Mac
Postgres has a "unix_socket_directory" setting located in postgresql.conf
Please verify that this setting exists and that the directory itself exists, then restart your server. If it doesn't exist, set it to something like /var/run (or another directory that exists) and restart the server.