pg_hba.conf for Postgresql from Windows Anaconda - postgresql

I've just installed Postgressql (9.5.4 vc14_0) and Psycopg2 (2.7.5 py36h74b6da3_0) and I'm trying to use them within my Anaconda environment on Windows 10.
Whenever I run psycopg2.connect("host=localhost user=postgres") in a python interpreter or just psql on the command line I get this error:
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
I've looked at other Stackoverflow questions regarding this, some answers say to look into a pg_hba.conf file although I haven't be able to find any. Where can I find a pg_hba.conf file for my Postgresql in my Anaconda Environment for Windows? If I have to make one, what should go in it? I haven't seen another SO question that uses the same Postgresql-Anaconda-Windows setup that I'm using.
Also I've looked into services.msc but haven't seen a service regarding postgresql.

I just ran into this error as well. Similar to what you did, I followed the installation page, ran conda install -c anaconda postgresql and received the same error in your post.
I have used postgresql through direct installation before, in osx and as far as I can recall, you could just psql into the database once the installation is complete.
Maybe this isn't the case for anaconda installations. I overcame this by initializing a new database system in a new, empty folder. In my case, I created a new folder in "\AppData\Local\conda\"
-- Initialize the database system
pg_ctl init -D <path_to_your_database_system>
-- Start the database
C:/Users/kerwei/AppData/Local/Continuum/anaconda3/envs/py36/Library/bin/pg_ctl -D <path_to_your_database_system> -l logfile start
NOTE: After playing around with for awhile, I realized that once you exit the conda environment, the database instance gets terminated too - without properly shutting down. As I don't use it for production stuffs, it doesn't really bother me. However, further steps can be taken to include the database booting and shutting down during conda activate or conda deactivate to make it less cumbersome.

Related

Cannot find PostgreSQL files, clusters, or service; what to do?

I am currently trying to install and setup PostreSQL on my computer (Debian 9) so I can use it as a local testing environment for Heroku. I have been having some problems. First, whenever I try to run psql (and similar commands), I get this error:
psql: 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"?
I have looked around on here for some fixes to this, such as this one, however I cannot find the postmaster.pid anywhere inside /usr. When looking for /var/run/postgresql, my search also turned up nothing.
Another promising answer was this one, however, I run pg_lsclusters, none appear. From a bit of searching, it says that this is probably due to initdb never being ran. I looked around for several ways to do this manually; none of them have worked or appear to exist on my system.
I have tried many of the "simple" things, such as sudo, sudo su postgres, removing and reinstalling the package and screaming at the computer.
What exactly is going on here? How do I fix it?
My OS (as mentioned before) is Debian 9, and the psql --version (which does work) is psql (PostgreSQL) 10.4 (Debian 10.4-2.pgdg90+1).

Postgres - Homebrew Install Cannot Find Server Files Multiple Versions

I am trying to use postgres on my machine and realized that some time ago I had installed the database software after running brew install postgres and receiving Error: postgresql-9.4.5_2 already installed. From there I decided to install homebrew/services to be able to run postgres in the background and successfully launched and closed the background job with
brew services start postgresql==> Successfully startedpostgresql(label: homebrew.mxcl.postgresql)
However, when I run postgres I received the error of:
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
When I followed an answer on SO, cat /usr/local/var/postgres/server.log I received the following error:
LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.5.
Which makes me think that I had an older version of PostgreSQL installed that needs to be removed.
I then tried psql and received:
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"?
And finally decided to init a new db with initdb /usr/local/var/postgres, but that didn't fix it, which resulted in following the original message and setting an env varible: export PGDATA=/usr/local/var/postgres. After trying postgres again, I receive
LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.5.
What this tells me is that there is clearly a version compatibility issue, which needs to be resolved in order to launch my postgres server, but I'm not sure what file paths need to be cleared or the proper way to clear them. Can anyone provide some guidance?
I had the same problem and I got it to work by running:
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
(this guide was good).

Postgres in Conda Environment (Ubuntu 14.04)

Being new to Anaconda, I am having some trouble properly setting up a conda environment. What I am interested in achieving is setting up an environment for a django application with a postgres database. The following command creates the environment:
$ conda create -n django1.7-webdev python=3.4 django=1.7 postgresql=9.1
This second command activates the environment:
$ source activate django1.7-webdev
At this point, though, when trying to run psql, I get the following error:
$ 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"?
How can I start PostgreSQL in the conda environment? The following command starts the PostgreSQL installed outside the activated conda environment, which is not what I want:
$ sudo service postgresql start
The postgresql documentation on starting servers is at https://www.postgresql.org/docs/9.1/static/server-start.html - before that, you might also need to initialize a database: https://www.postgresql.org/docs/9.1/static/creating-cluster.html
The conda package should include any binaries necessary to follow those directions. Moreover, these binaries should already be on PATH, since you are activating the environment.
In general, if you're starting a command with sudo to interact with conda, something is wrong. Unless you are trying to do some centrally-owned install that several users use, conda should never require admin rights.

Postgres cant connect to server: No such file or directory

I'm running Debian server and use SSH to manage it. Today I tried to install Postgres and follow this steps to do it:
apt-get install postgresql
su - postgres
psql
After the last command I got:
psql: 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"?
I found several solutions in the Web, but all of them doesn't works for me. As example I found, that I need to delete "postmaster.pid" in here:
/usr/local/var/postgres/postmaster.pid
But I have no such directory as "postgres" in my "var" folder...
Please, help...:(
What you did is correct and normally sufficient except when something goes wrong with the automatic creation of the first cluster by apt-get install postgresql. Often there is an error message like this in the middle of the success reports:
Error: could not create default cluster
Since you can't have done any work with postgres yet, purge the packages with
apt-get purge 'postgresql*'
then reinstall with
apt-get install postgresql
but this time, pay close attention to any error message that would imply that the initial cluster was not created, that will give the actual reason of the problem.

Unable to start sever, likely due to misplaced .conf. How do can I verify the cause and find/replace .conf?

I'm new to psql, and am having some issues that I think are being caused by a misplaced .conf file. When I tried to log into a database I created earlier I get an error
$ psql corporation
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
Based on the psql docs it looks like the server isn't running and ps confirms this. Since I don't remember having to start it last time I used psql I was a little confused, but it seemed easy to fix. Unfortunately, my attempts to start the sever have not worked. Using the first method suggested by the docs gets me
$ postgres -D /usr/local/pgsql/data
postgres cannot access the server configuration file "/usr/local/pgsql/data/postgresql.conf": No such file or directory
While the second method results in
$postgres -D /usr/local/pgsql/data >logfile 2>&1 &
[1] 3165
Ps confirms that neither of these methods started postgres, and when I tried to open the database anyway, to double check, it returns a slightly different error message than before.
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"?
[1]+ Exit 2 postgres -D /usr/local/pgsql/data > logfile 2>&
How to start PostgreSQL server on Mac OS X? seems related, but has some gaps. Just running initdb wasn't enough, and I don't seem to have a .conf.sample. Do I just need to create a new .conf from scratch or what?
For reference I'm running Snow Leopard, I originally tried to manually instal psql, but ended up installing brew then brew installing psql.
Have you tried doing a find?
sudo find / -name postgresql*