Postgres in Conda Environment (Ubuntu 14.04) - postgresql

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.

Related

How to run PostgreSQL after install on a clean Ubuntu build?

I've just installed Ubuntu, installed Conda, several packages including Django and PostgreSQL via Conda (with Conda installed PostgreSQL). That's it, nothing else.
I'm trying to follow the instructions here: https://github.com/rdkit/OCEAN. Rather than creating a virtual environment I've created a Conda one instead. I'm not sure if that's going to make any difference.
Also please note: this is a clean build. I have not activated anything or created any DB user etc. All I've done is activate the Conda env of choice and started installing the packages listed on the link above.
I'm having problems with the initial PostgreSQL instructions recreated here...
Get a clone of OCEAN from the Repo:
git clone https://www.github.com/rdkit/OCEAN.git
cd OCEAN
Create a PostgreSQL-User, the database for OCEAN and fill the OCEAN-DB:
# create PostgreSQL-User for OCEAN
# password 'ocean_pw' should be used when asked,
# according to database-entry in settings.py
createuser -P -s -d -r -e ocean_user
# create PostgreSQL-Database for OCEAN
createdb --owner=ocean_user ocean
When I try createuser -P -s -d -r -e ocean_user and then add the required password (in the Git link) I get the error:
createuser: error: could not connect to database postgres: could not connect to server: No such file or directory. Is the server running locally or accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I have a Conda environment and on a very clean Ubuntu machine. The last time I touched a DB was years ago. How can I resolve this?

pg_hba.conf for Postgresql from Windows Anaconda

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.

Starting a postgres SQL 9.6 Server on Amazon Linux returns unrecognized service

I am attempting to start a Postgres SQL server on amazon Linux using the command
sudo service postgresql start
I installed the server using this method. I have added it here for simplicity
sudo rpm -i https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm
and then
sudo yum install postgresql96-server.x86_64
after which i did this to install the command line tools for postgres
sudo yum install postgresql96.x86_64 postgresql96-libs.x86_64
Any suggestions on how I can start the server ? I usually start the server using
the command
sudo service postgresql start
however its not working in this case as it says "Unrecognized service"
I then tried this
postgres -D /usr/local/pgsql/data
postgres: could not access directory "/usr/local/pgsql/data": No such file or directory. Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
Having the same issue, or similar. May be I installed pgsql from source, don't remember. We could make our own service start files. How? Let's find out! >>RTFM<< starting with what we already know:
man service
which leads us to chkconfig(8), so
man chkconfig
and it gives us an option
chkconfig --add ${svcname}
to add a brand new service under a name we choose!
But before we do, we might actually want to check what's already there. With
service --status-all
we get a list of all known services and their run status. And I found "postmaster" in my list, and as you might know, the PostgreSQL master server to connect to used to be called "postmaster". Yet, when I try
service postmaster status
it also tells me it doesn't know such service. OK, forget it -- for now -- just let's move on with making our own! But I still want to peek what there is in run-level 3 (normal server run level). So I go
ls -1 /etc/rc.d/rc3.d |fgrep post
and there I find: "K36postgresql95"! So, accordingly our service name should be "postgresql95". Trying that:
service postgresql95 status
it says now "postmaster is stopped". Confusingly the name the service reports for itself both in service --status-all and when we individually inquire for it is different than the name used to actually address it in the service command. Good to know. Easy enough to search /etc/rc.d for the name of interest.
service postgresql95 start
now starts the service. And check with
psql -U ${pguser} ${pgdb}
and I find that working. So now all I need to do is enable that service at system boot to auto-start
chkconfig --levels 3 postgresql95 on
and that works, doesn't it?
PS: It doesn't matter that I happen to run version 9.5
I recently installed PostgreSQL 9.2.24 on Amazon Linux 2 and I had to initialize the database manually before being able to create ROLE and DATABASE as I normally would on Ubuntu.
// initialize database after installing with yum
$ sudo postgresql-setup initdb
// start
$ sudo systemctl start postgresql.service

how to install Odoo 9 on ubuntu?

I have pre installed postgres , postgres-9.3 and pgadmin on port 5432 and 5433 .
uninstall them then trying to install odoo 9 using http://openies.com/blog/install-openerp-odoo-9-on-ubuntu-server-14-04-lts/
this tutorial .
but when i ttrying to execute command
createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo
then it gives following error :
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
"/var/run/postgresql/.s.PGSQL.5432"?
sudo netstat -nltp | grep 5432 is not showing any result .
pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
1. Introduction
In this tutorial I will learn you how to install Odoo 9 on Ubuntu 14.04. The script that you will use is based on the code from André Schenkels but has been updated and improved.
2. Downloading the script
The first step is to download my script from GitHub and to add the code in a new .sh file on your Ubuntu machine, wherever you’d like this.
For example right under /home. Open up an Ubuntu terminal and cd to the directory where you’d like to keep the script and then create the file:
sudo wget https://raw.githubusercontent.com/Yenthe666/InstallScript/9.0/odoo_install.sh
If you’re curious about how the whole code looks and works you can find it on my Github account.
Now open up the file and edit the parameters to your liking:
sudo nano odoo_install.sh
There are some things you can configure/change to your likings at the top of the script. You can choose if you wish to install Wkhtmltopdf or not, which version you’d like, where the location is and most importantly what the master admin password is. Tip: always modify this for every Odoo you install!
3. Making the Odoo installation file executable
The next step is to make this file executable. After you’ve made it executable you can execute it and everything will be installed automatically.
do this with the following command:
sudo chmod +x odoo_install.sh
4.Running the script
Now that the code is in your file and the file is executable you simply have to execute it with the following command:
./odoo_install.sh
You will see that the script automatically starts updates, downloads required packages, creates the user, downloads the code from Github, …
Give the script a few minutes to configure and install everything and eventually you will see something like this:
You now have a fully functional Odoo V9 on your system! Congratulations.
Odoo V9
5. Extra information
In the script you saw there was an option to change the Odoo port (OE_PORT). When you’d change this port number to 8070 in the install script it would be applied to /etc/your-config-file.conf and this would give you the ability to change the default port.
To apply these changes you should do the following:
The -c will change the configuration and memorize what you’ve changed under /etc/your-config-file.conf. Because my port was set to 8070 this is telling the Odoo that it should run on port 8070. When you would now open up your browser and navigate to http://localhost:8070/ you will see it is running there:
Odoo V9 alternative port
This issue comes form installing the postgres package with out a version number. Although postgres will be installed and it will be the correct version the script to setup the cluster will not be run correctly. It's a packaging issue. If your comfortable with Postgres there is a script you can run to crete this cluster and get postgres running however if your like me then you do it the easy way. First purdge the old postgres install. The issue currently lies with 9.1 so I will assume that's what you have installed
sudo apt-get remove --purge postgresql-9.1
Now simply reinstall
sudo apt-get install postgresql-9.1
Note the package name with the version number. HTH.
I have installed odoo using http://openies.com/blog/install-openerp-odoo-9-on-ubuntu-server-14-04-lts/ got no issue with the fresh ubuntu 14.04 LTS.
But, you need to check that there is no postmaster.pid in your postgres directory, probably /usr/local/var/postgres/
Remove this and start server using
rm /usr/local/var/postgres/postmaster.pid
It should work.
Check this to install odoo 10 in ubuntu 16.04 LTS
Bitnami ODOO, easy to install in your Machine.
Download from Here
It is compatible with preinstall postgresql.
As mentioned before you can use one simple script to install Odoo of any version (9, 10, 11).
Follow the steps:
Log in to your system and work as an superuser: sudo su
Update the system: apt-get update
Download the script. You can change to the version of your choice:
wget https://raw.githubusercontent.com/Yenthe666/InstallScript/11.0/odoo_install.sh
Run the script: ./odoo_install.sh
Now you can access Odoo at http://serverIP:8069
If you are running it locally that would be 127.0.0.1:8069
The next steps would be to configure the Apache/Nginx or another server to point a domain to the Odoo instance. Also, remember to set the proper access rules on your server (for example on Amazon that would be by opening the port 80 and 8069 in the security rules). It is also wise to change the default password in Odoo config from admin to something more secure.
If you used the script without editing your Odoo config file would be installed in /etc/odoo-serfer.config. Use nano, vi or another editor to change the default settings.

How to run postgres on centos when installed via YUM repo as default daemon user

With a freshly installed version of Postgres 9.2 via yum repository on Centos 6, how do you run postgres as a different user when it is configured to run as 'postgres:postgres' (u:g) out of the box?
In addition to AndrewPK's explanation, I'd like to note that you can also start new PostgreSQL instances as any user by stopping and disabling the system Pg service, then using:
initdb -D /path/to/data/directory
pg_ctl start -D /path/to/data/directory
This won't auto-start the server on boot, though. For that you must integrate into your init system. On CentOS 6 a simple System V-style init script in /etc/init.d/ and a suitable symlink into /etc/rc3.d/ or /etc/rc3.d/ (depending on default runlevel) is sufficient.
If running more than one instance at a time they must be on different ports. Change the port directive in postgresql.conf in the datadir or set it on startup with pg_ctl -o "-p 5433" .... You may also need to override the unix_socket_directories if your user doesn't have write permission to the default socket directory.
pg_ctl
initdb
This is only for a fresh installation (as it pertained to my situation) as it involves blowing away the data dir.
The steps I took to resolve this issue while utilizing the packaged startup scripts for a fresh installation:
Remove the postgres data dir /var/lib/pgsql/9.2/data if you've already gone through the initdb process with the postgres user:group configured as default.
Modify the startup script (/etc/init.d/postgresql-9.2) to replace all instances of postgres:postgres with NEWUSER:NEWGROUP.
Modify the startup script to replace all instances of postgres in any $SU -l postgres lines with the NEWUSER.
run /etc/init.d/postgres initdb to regenerate the cluster using the new username
Make sure any logs created are owned by the new user or remove old logs if error on initdb (the configuration file in my case was found in /var/lib/pgsql/9.2/data/postgresql.conf).
Startup postgres and it should now be running under the new user/group.
I understand this might not be what other people are looking for if they have existing postgres db's and want to restart the server to run as a different user/group combo - this was not my case, and I didn't see an answer posted anywhere for a 'fresh' install utilizing the pre-packaged startup scripts.