Start a postgres server with pgadmin - postgresql

I'm trying to start a postgreSQL server in Debian 10 in order to access this database: https://catalogofraneitalia.wordpress.com/database/.
I have never used postgreSQL before and I have tried to follow the instructions I found on the internet. This is what I have run up to now:
sudo apt -y install gnupg2
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt -y install postgresql-11
sudo apt install postgis postgresql-11-postgis-3
I checked that postgreSQL is active, enabled and accepting connections
sudo su - postgres, psql and create user username with superuser password 'password' with the username and password chosen
sudo apt install pgadmin3 pgadmin3-data
I opened pgadmin and I cliked on Add server, inserting the username and password previously created and I received the message Peer authentication failed for user "username"

the correct steps to install pg are in the official site: https://www.postgresql.org/download/
Follow the steps on screen, once initialized you can open the port (listen_address and pg_hba.conf), restart the service, and done... you can connect from other machine.
Other thing, pgadmin3 is deprecated, try using pgadmin4.

Related

How do i install Postgres on Ubuntu and create a superuser?

I have successfully installed Postgres on Ubuntu 20.04 by running the following commands:
$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib libpq-dev
which was successful. I then run the command:
$ sudo service postgresql start
which was also successful.
However, the command
$ sudo -u postgres createdb $USER
failed. The error message was as follows:
createuser: error: could not connect to database template1: 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"?
Please help me out.

Can connect to Azure VM on Port 22 but not on port 5111

I have the network security port open on 5111:
I have firewall open on port 5111:
my postgresql is on port 5111:
I've restarted the server, ran diagnostics (nothing found from azure)
I can ssh to my VM but can't connect to postgres:
Any help is appreciated, thank you!
In case outbound rule is needed, here it is configured:
What helped was I installed netstat and executed command netstat | grep 0.0.0.0 to see if postgres was running and listening. I found out that it wasn't listening at all. Found out that the listen_addresses needed to be listen_addresses = '*'. That still didn't work, so I reinstalled it with these steps and it worked: https://gist.github.com/luizomf/1a7994cf4263e10dce416a75b9180f01
# Update all your packages
sudo apt update
sudo apt upgrade -y
# Add postgresql repository and key
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Update again
sudo apt-get update
# Install pgadmin4
sudo apt install pgadmin4
# Install postgresql-13
sudo apt-get -y install postgresql-13
# Check version to see if it's correct
psql --Version
# Allow remote connections
# edit line #listen_addresses to listen_addresses = '*'
sudo nano /etc/postgresql/13/main/postgresql.conf
# edit file
sudo nano /etc/postgresql/13/main/pg_hba.conf
# add line at the end (change 192.168.0.0/24 to your network or 0.0.0.0/0 to all)
host all all 192.168.0.0/24 md5
# FOR SSL: add line at the end (change 192.168.0.0/24 to your network or 0.0.0.0/0 to all)
hostssl all all 192.168.0.0/24 md5 clientcert=1
# Restart postgres
sudo systemctl restart postgresql
# Access psql to create users, databases and passwords
sudo -u postgres psql
# Add a stronger password to default postgres user
alter user postgres with encrypted password 'the_postgres_user_password';
# Create user
create user your_username with encrypted password 'your_user_password';
# OR a superuser
CREATE ROLE your_username WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'your_user_password';
# Create a database
CREATE DATABASE db_name2 WITH OWNER your_username;
# Grant permissions to user on database
GRANT ALL PRIVILEGES ON DATABASE db_name TO your_username;
# Read security tips here
# https://www.digitalocean.com/community/tutorials/how-to-secure-postgresql-against-automated-attacks

None of the supported PHP extensions (PgSQL, PDO_PgSQL) are available

i have enabled extension=php_pdo_pgsql.dll and extension=php_pgsql.dll in my php.ini file but still unable to get adminer to work.
and also sudo service apache2 restart
sudo apt-get install php7.0-pgsql
cd /etc/postgresql/9.5/main
sudo nano pg_hba.conf
local all postgres peer
should be
local all postgres md5
sudo service postgresql restart
then you good to go :)

How to access mongodb remotely in linux

I have successfully installed mongodb into my linux machine.
Please suggest how to access it remotely.
I worked on it and searched for it. Finally came up with following solution.
Importing the Public Key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Creating a List File
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
Installing and Verifying MongoDB
sudo apt-get install -y mongodb-org
service mongod status
Creating a user
use admin
db.createUser({user:"<username>", pwd:"<password>", roles:[{role:"root", db:"admin"}]})
Try to Login
mongo -u <username> -p <password> --authenticationDatabase admin
Set vi /etc/mongod.conf
# Comment bindIp with #
service mongod restart
Allow connections on port 27017, MongoDB default port
ufw allow 27017
ufw status
Enable mongodb authentication on vi /etc/mongod.conf
security:
authorization: enabled
To access mongodb remotely the command is:
mongo -u <username> -p <password> <ip-address>:27017/<collection-name>

Postgresql installation Error Ubuntu 14.04

I've tried to install Postgres for the past few days on Ubuntu 14.04. I have followed this set of commands:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get purge postgresql
sudo apt-get -f install
sudo apt-get install postgresql
With no such luck... The error message I get is as follows:
postgres#CouchVictory:~$ psql
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've also tried the suggestion here and I've made sure that my shell is a login shell. Any suggestions?