I'm trying to install postgreSQL(11) server on my local machine.I have downloaded PgAdmin 4(Mac) from the official website and installed it.
When I open the pgadmin the server is opening on random ports like 55957,55062 etc, not on 5432.
I have edited my "PostgreSQL.conf" and changed the listen address=* and port =5432 ,but I could not able to restart the service.
When I type "sudo service postgreSQL restart" it was showing "Sudo : Service command not found"
Also "Sudo command not found".
I don't have much experience in installing postgreSQL ,Can anyone please let me know what I'm doing wrong and let me know how I can add the server in postgres.
Note: I have opened pgadmin - select add new server - localhost as server name and User and DB as postgres.But when I put 5432 as port it was giving the common error "Whether TCP/ip accepting on 5432" and when I put the port where the pgadmin server is currently running (127.0.0.1:55097) it was getting timed out exception.
Related
I am new to Ubuntu operating system and trying to install postgresSQL in my system.
After completing the installation and entering postgres mode when I enter the command pgsql, it gives me this 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 "/var/run/postgresql/.s.PGSQL.5432"?
what could possibly be wrong??
Probably the postgresql server is not running; you can run netstat -adp to see if postgres is listening on port 5432.
If it isn't, then it most likely isn't running; systemctl status postgresql will help identify if it is even installed, and if it has run into any issues (for further details, see https://mydbanotebook.org/post/troubleshooting-01/)
If it is running and seems healthy, then it might not be configured to accept connections in whichever way you are connecting (which user, database, host/network etc) - see details about the pg_hba.conf file that includes rules for this - https://www.postgresql.org/docs/9.1/auth-pg-hba-conf.html
After install, you must create an instance with initdb.
Later, change the listen_address to *, restart the service and now you can check the port.
Check the pg log for the message: "postgres is ready to accept connections"
I have PostgreSQL 11 and PGadmin 4 installed on windows. Currently I'm connected to a AWS server which hosts all of my data.
I want to create a local server (localhost) as a testing environment where I can experiment. I can't seem to do it though, and the other similar questions on stack don't help. Here's what my process is:
in pgAdmin, right click 'Servers' and go Create>Server
On the 'Create - Server' pop up box, i type in Name: Localserver. For 'connection' I type localhost. Port I leave as default '5432', db: postgres, username: postgres password: empty
click save.
however, I get an error:
Unable to connect to server:
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
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?
What should I do? I am the admin if that makes a difference.
As a new Postgres user, I did not understand how to make use of Postgres on Ubuntu. So I'm just going to chime in and help out other newbies who perhaps cannot figure out how to work with Postgres on Linux. If you're using Windows, steps should be similar.
Before you get to using PgAdmin, a bit of configuration is required. Most will happen in your terminal at first.
Open a terminal using Ctrl + Alt + T if you're on a PC. Or just pres ALT + F1 and begin typing Terminal.
Let's start with the basics first and make sure you have proper
installation.
1. Installing Postgres Latest
1.1 update the system software packages
sudo apt update
1.2 install latest version of PostgreSQL from default Ubuntu repositories
sudo apt install postgresql
the installer will create a new PostgreSQL collection of databases
that will be managed by a single server instance
Default data directory : /var/lib/postgresql/your-version/main
Configurations files : /etc/postgresql/your-version/main
2. Checking if Postgres Service is Installed
2.1 Check if Postgres is Active
sudo systemctl is-active postgresql
You should see : active
2.2 Check if Postgres is enabled
sudo systemctl is-enabled postgresql
You should see : enabled
2.3 Check Postgres Service status
sudo systemctl status postgresql
You should see : active (exited) marked in green
2.4 Check if Postgres is ready to accept connections
sudo pg_isready
You should see : /var/run/postgresql:5432 - accepting connections
3. Configuring Postgres Authentication
3.1 Opening the pg_hba.conf as SUPERUSER
sudo code --user-data-dir=~/root /etc/postgresql/13/main/pg_hba.conf
I'm using visual studio code so for me code is vsc codename. If you're using vim or sublime just replace code with your text editor name.
3.2 Configuring pg_hba.conf
Notes: you shouldn't need to change anything here, just make sure your
configuration files matches the following lines :
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Hit save and close.
3.3 Restart Postgres Service
sudo systemctl restart postgresql
4. Create NEW Server
For me, this is where all my confusion was. Before you use PgAdmin,
you need to create a server in your terminal, then you can connect and
manager it with PgAdmin just like you would with PhpMyAdmin. It's
actually easier.
4.1 Access the PostgreSQL database shell
sudo su - postgres
psql
You will then see this : postgres=#
4.2 Creating new server and user
postgres=# create user bob with superuser password 'admin';
That's how you create new user and server in Postgres. Let's move on to PgAdmin.
5. Installing pgAdmin4
5.1 Add public key for the repository
curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
Notes : if you don't have curl your Ubuntu will give you the command to install it
5.2 create the repository configuration file
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
5.3 install pgAdmin4
sudo apt update
sudo apt install pgadmin4
5.4 run the web setup script installed with the pgadmin4 binary package
sudo /usr/pgadmin4/bin/setup-web.sh
It will asks you for your email address and password. This email and
password is required to login to the PgAdmin4 web interface
6. Accessing pgAdmin4 Web Interface
6.1 Open your favorite browser
type in the address of the PgAdmin web interface. It usually looks like this
http://127.0.0.1/pgadmin4
Note : After installation the web setup script will tell you exactly
where to access the web interface.
When you see the login screen, enter the email and password you've chosen during the web setup script.
6.2 Adding New Server Connection
6.2.1 Click on Add New Server
6.2.2 Under General tab enter a name for your server. ANY name you would like, it doesn't matter. You could enter PgServer1 or whatever. Don't change anything else.
6.2.3 Switch to Connection Tab
Hostname/ Address : localhost
Port : 5432
Maintenance database : postgres (always)
Username : **bob** (the username youve chosen at 4.2)
Password : admin (or any password you chose at 4.2)
Hit Save.
Voila! You should be connected successfully. If not, just open terminal and create a new user like we did at 4.2
Notes : to create databases is very easy just right click on your
servername
create > databases
Useful Resources & Tutorials
PostgreSQL Fundamentals : Queries and the likes
PostgreSQL & JSON : useful for dealing with JS apps
PostgreSQL & Nodejs : Create realtime apps with nodejs and socket.io
More PostgreSQL Nodejs
https://github.com/supabase/realtime
https://whatsyourssn.com/posts/real-time-app-socket-postgresql/
UPDATE 2023
While following my own tutorial I ran into certificate issues at step 5 when I tried to create the repository file. The full error I was getting was this.
I want to post the solution that worked for me here.
This is probably one of two things.
You have set up a Postgres server, but have not adjusted listen_addresses in your postgresql.conf file, or
You have not set up a Postgres server on your local machine. ("Create Server" is a bit misleading, it should probably be "Create Server Connection".)
Usually a “connection refused” error indicates that the database server is either 1) not running, or 2) configured in such a way that it is not listening to the right port or IP address. Be sure to check ps -ef to see if Postgres is running, and also look at postgresql.conf to see if port and listen_addresses are set properly.
make sure the postgres service is running.
example in Linux : systemctl enable postgresql.service
Why? Attempting to connect to the server that is not running.
Action: Start your PostgreSQL server.
The path in the command below points to the data directory configured during the installation of PostgreSQL. Run this in Windows cmd.
pg_ctl -D "C:\user\PostgreSQL\data" start
>server started
After this go to pgAdmin and follow the initial steps as in question.
Create Server
Under General: Name: mytestServer
Under Connection: Hostname: localhost, Password: yourPassword,
keep other settings as default
Hit save
If you haven't, then first install the Postgres server on your machine. For windows, this is the currently active link for downloading the installation package: https://www.postgresql.org/download/windows/
As other answers here pointed out, PgAdmin is only a interface for using the Postgres server. Once you install the server locally, you'll be able to see the server on the left hand side pane after restarting PgAdmin.
I am new to PostgreSQL, and I want to use it on my personal laptop for personal projects. I use SQL Server and SQL Server Management Studio at work, coding-wise I'm ok but I need some help with setting up the localhost on my laptop.
So I downloaded PostgreSQL and installed it along with pgAdmin that came with the package.
During installation, it asked me to create a PostgreSQL superuser password, which I did.
Then I tried creating a new server using pgAdmin as follows:
General Tab:
Name: localhost
Server Group: Servers
Connect Now?: check
Connection Tab:
Host name/address: localhost Port: 5432
Maintenance database: postgres
Username: postgres
Password: [blank]
But when I click save I'm getting an error message:
Unable to connect to server: could not connect to server: Connection
refused (0x0000274D/10061) Is the server running on host
"localhost"(::1) and accepting TCP/IP connections on port 5432? 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?
Also tried replacing the password field with the Superuser password, getting the same error message.
Would greatly appreciate it if anyone offers any insights into this problem, I might just be a noob when it comes to server setups...
Thanks,
Mike
Update:
I believe there's a service I need to start as suggested by #Scott Moniz. I went into services.msc, tried to start the service postgresql-x64-10 - PostgreSQL Servier 10, and I got this error message:
"The postgresql-x64-10 - PostgreSQL Server 10 service on Local
Computer started and then stopped. Some services stop automatically if
they are not in use by other services or programs".
I then tried editing the property of the service, by changing the Log on as option to Local System Account and tried starting the service again, still got the same error message.
I'm using Windows 10 Home edition, it this helps to resolve the issues in anyway
Thanks,
Mike
Are you sure the database service is running and listening?
CLick Start>Run> type services.msc
Look for a postgresql service - if it does not say started right click it and click Start.
Alternatively you can restart your computer and the service should start if it is set to 'Automatic'
New to web development. Trying to connect and register new server for pgAdminIII. (using cloud 9 ide)..
I get this error when viewing in the browser..
_PG::CONNECTION BAD _
could not connect to server: Connection refused Is the server running on
"localhost" (::1) and accepting TCP/IP connections on port 5432?
could not connect to server: Connection
refused Is the server running on host "localhost"
(127.0.0.1) and accepting TCP/IP connections on port 5432
PS. trying to access via new user "ubuntu" SUPERUSER created..
How can I fix this?
PPS. On cloud 9's community forum, an employee says..
"Only ports 8080, 8081 and 8082 are open for workspaces so if you want to access the DB externally you'll need to run it on one of these ports. Make sure you can access it with curl from a local terminal and ensure it's listening on 0.0.0.0 not 127.0.0.1, as the latter only allows local connections."
Lastly, their ide comes with postgres installed, all I needed to do, was set it up..
How do I use the above info while trying to register the new server in order to use the gui?
Let me know if I need to include anything else.
Thanks.
You should enable postgresql service by performing sudo service postgresql start.
After enabling, you can access the console using sudo sudo -u postgres psql and CREATE ROLE ubuntu LOGIN REPLICATION CREATEDB CREATEROLE SUPERUSER; to allow Rails take advantage of your database.
Rails also complains about template read error after creating ubuntu role.
To fix the template error, read up on this.
You should get PostgreSQL server up and running in no time. Happy coding!
Edit:
You should only use localhost for local and system resources (i.e. psql, etc.) while 0.0.0.0 is for everything else like running Rails or Apache server.
I just installed PostgreSQL on Snow Leopard and can't connect to the database server via pgAdmin 3.
I'm on my local machine, however I keep getting this error:
Could not connect to server: connection refused. Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5423?
I'm a bit of a noob when it comes to Postgres, so I'm not really sure what the problem is.
I can, however, log in through the command line, via psql -U postgres, and start and stop the server successfully.
Any help would be much appreciated.
The error message pointed out that you tried to connect to server on port 5423. However, postgres server listens on 5432 by default.
From your above comment (SHOW port; gives me "5432"), I think you need to change the port to 5432!
UPDATE: Tuan Dang spotted it. I'll leave this answer in place in case it helps someone else for whom the issue isn't quite the same.
Since you can connect via the command line, run:
SHOW port;
from psql. You'll probably see that the port is not 5432. You need to connect to the port PostgreSQL is actually running on from your application.
It's also possible that it just isn't listening on TCP/IP. Run:
SHOW listen_addresses;
to see what it's listening for.
The reason you can connect via the command line is likely to be because the command line psql you're using is connecting over a unix socket (since you didn't specify a host) and your app is connecting via tcp/ip.