Facing issues while installing postgresql in Ubuntu - linux

I want to install postgresql in ubuntu but facing lot of issues,searched a lot but still no success,so when I try to install I used below commands:
sudo su -
apt-get install postgresql-9.5
update-rc.d postgresql enable
When the installation completes it gives me the error of
9.5 main 5432 down postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log
and after when I give following command
sudo -i -u postgres
psql
it gives me
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"?
How can I fix this?

In Postgres, you need to connect as a specific user called postgres.
Try doing this : sudo -i -u postgres and then use psql

Related

How to use redis in windows?

I want to use redis in my nodejs application.I have installed npm package for redis. But while starting application i am getting error as
Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
Install WSL on windows. Can do this through Microsoft store. Example below is using Ubuntu and assumes you have installed the distribution with an open terminal. Ubuntu can be started by normal ways of starting applications on Windows.
> sudo apt-get update
> sudo apt-get upgrade
> sudo apt-get install redis-server
> redis-cli -v
This performs updates to ubuntu on your machine and installs redis.
The last command should output something like: redis-cli 6.2.5
If for some reason redis is not running, execute sudo service redis-server restart in ubuntu terminal

how to connect redshift database to a bash script running on ec2 instance

I have couple of sql queries and I want to run them against amazon redhshift , The base script will be on my ec2 instance and will be triggered from there. How do I provide the connection to the database and the run the bunch of sql scripts ? Please guide
The easiest way to do this is to install postgres on the ec2 instance and then use the psql command line tools to connect to Redshift.
Install postgres (yum and apt-get, pick the appropriate one for your Linux type):
sudo apt-get install postgresql postgresql-contrib
sudo yum install postgresql postgresql-contrib
Here's a line from one of my bash scripts that does this. Check out the psql man page for all the options and ways to connect.
PGPASSWORD="$RS_password" psql -a -v ON_ERROR_STOP=1 -h "$RS_DNS" -v schema=public -p "$RS_port_no" -U "$RS_user" -d "$RS_db" -f /tmp/math_$$.SQL || { echo psql command 1 failed ; exit 1; }
There is also a -c option to pass the SQL on the command line.

Cannot connect to the 5432 port postgres ubuntu

Well I am trying for hours to install and configure postgres in ubuntu but getting below 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 tried almost every solution I found but still no success.
Below are the commands I have used to install postgres:
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo -i -u postgres
psql (After this I got an error)
The error arises during the installation of postgres.Kindly give suggestions or resources through I which I can fix this!

2 Postgres Servers on local machine. How to uninstall or disassociate one?

Through some mishap I seem to have 2 separate Postgres servers on my local Ubuntu machine. PGAdmin connects to one (localhost:5432), which can also be reached with the terminal through: sudo -u postgres psql postgres -W -h 127.0.0.1 -p 5432
The other "default" server can be reached through the terminal with just sudo -u postgres psql postgres
For other info, locate bin/psql returns:
/usr/bin/psql
/usr/lib/postgresql/9.5/bin/psql
I suspect the latter of those directories is the Postgres 9.5 instance I really want to use, and the one I want to associate with without needing to specify -h 127.0.0.1 -p 5432. The other can be removed completely. How do I resolve this?
You can use the package manager to remove it.
From terminal, you can list the installed versions of PostgreSQL executing:
$ apt list --installed | grep postgresql
The ones with the format postgresql-X (where "X" is the version) is those to remove. You should be able to do it with the apt purge command.
For example, to remove the version 9.6, you have to execute:
$ sudo apt purge postgresql-9.6
/usr/bin/psql should be a symbolic link to the most recent version installed (/usr/lib/postgresql/9.6/bin/psql).

Configure postgresql on ubuntu using a terminal

I installed Postgresql on my virtual machine running ubuntu using the command
sudo apt-get install postgresql-client
Next, I need to set up the connection string, login roles, databases, etc... However, I need to do it in the terminal since I don't have a GUI. Does anyone know how to do this or can point on a tutorial on how to do so??
Thank you in advance!
Follow these command:
Install and Configure Postgres
sudo apt-get install postgresql
This command will install postgres 9.1 by default in ubuntu 14.04 or any debian distribution. if you want to use any specific version of postgres(i.e 9.3, 9.4) you need to update the source list. for example to install postgres-9.4 you can follow below steps.
Create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository using vim or nano editor
deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main
Import the repository signing key, and update the package lists
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
and update the packages using
sudo apt-get update
after that you can search/install the available/supported postgres version
sudo apt-get install postgresql-9.4
After installing postgres 9.4, change to the postgres user so we have the necessary privileges to configure the database
sudo su - postgres
Now create a new database user with access to create and drop database.
createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo
Enter password for new role: ********
Enter it again: ********
Finally exit from the postgres user account:
exit
man psql or the official psql docs. Also see the tutorial.
On the server run the commands below.
sudo apt-get update
sudo apt-get install -y postgresql postgresql-contrib
Create a database and a user to access it
I prefer to create one user per database for security.
Replace DATABASE_NAME_HERE and USER_NAME_HERE with the values that you want to use
this will prompt you for a database password
sudo -u postgres createuser -P USER_NAME_HERE
sudo -u postgres createdb -O USER_NAME_HERE DATABASE_NAME_HERE
Test connecting to Postgresql
psql -h localhost -U USER_NAME_HERE DATABASE_NAME_HERE
Postgresql will ask you for your password. Then you should see:
psql (9.3.5)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.
DATABASE_NAME_HERE=>
To exit type:
\q

Resources