How to set up localhost server and database for PostgreSQL? - postgresql

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'

Related

DBeaver localhost PostgreSQL connection refused

I just installed DBeaver on my personal computer and am trying to create a PostgreSQL database.
I entered the following in the Connect to database window:
Host: localhost
Port: 5432
Database: postgres
User: postgres
Those values were all pre-filled defaults, so I left them and clicked the Test Connection... button.
When I click the Test button an error window opens, saying, "Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. Connection refused: connect"
I tried setting my own db name and credentials, but get the same results.
How do I set up a local PostgreSQL database in DBeaver?
DBeaver does not allow to setup a local PostgreSQL server or instance: it allows to connect to an existing server or instance. If the PostgreSQL instance does not exist you should install PostgreSQL binaries and create a new database instance with initdb.
If your operating system is Windows 10 Home, you have to use 192.168.99.100 instead of localhost.
Answer from here - https://www.reddit.com/r/dbeaver/comments/fi8h0q/new_dbeaver_install_how_to_set_up_first/.
Dbeaver is just a client to the server. You need to setup the server itself first.
https://www.postgresql.org/
Download and setup the server then you can connect to it with DBeaver and do what you want to do.
I got the same, and then I remembered that I didn't start postgres with the script

postgreSQL server not loading

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.

Is there any issue using the same postgresql database for two different servers?

I am using postgres database which is accessed by jboss and tomcat server.
My server accidentally restarted and then postgres service was not showing in the services list.
When I tried to open postgres local host server using pgadminIII it showed following error:
Server doesn't listen
The server doesn't accept connections: the connection library reports
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?
If you encounter this message, please check if the server you're trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.
For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you'll need to set the "tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart the server process to make the setting effective.
If you double-checked your configuration but still get this error message, it's still unlikely that you encounter a fatal PostgreSQL misbehaviour. You probably have some low level network connectivity problems (e.g. firewall configuration). Please check this thoroughly before reporting a bug to the PostgreSQL community.
Does this problem arise due to accessing same DB by two different servers?
My server accidentally restarted and then postgres service was not
showing in the services list.
You can't connect because it's not running. You can have as many clients connecting to a PostgreSQL server as your hardware can support - there is no problem with that.
Restart your PostgreSQL service. If it won't, check the logs for why. If you don't know where your PostgreSQL logs are now is a good time to find out. I can't tell you how to restart the service because you haven't said what OS you are running or how you installed PG. Check your documentation.

PG::CONNECTION BAD connecting to pgAdminIII cloud 9 IDE

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.

HEROKU POSTGRES error: Connection refused Is the server running on host "..compute-1.amazonaws.com..." and accepting TCP/IP connections on port 5432?

I have been trying for weeks to figure out what's the issue, but I cannot seem to fix this.
I am developing a web app, and I have deployed to production using Heroku. I'm using Heroku Postgres for my database, and I'd like to psql into that hosted database from my local machine to make changes to it. I have tried from both Mac OS X and Linux Mint.
However, no matter what I try, I keep getting the following error:
---> Connecting to HEROKU_POSTGRESQL_ORANGE_URL (DATABASE_URL)
psql: could not connect to server: Connection refused
Is the server running on host "ec2-***-**-***-**.compute-1.amazonaws.com" (***.**.***.**) and accepting
TCP/IP connections on port 5432?
I'm starting to think that I may have to SSH into the Amazon EC2 instance and change the Postgres configuration? Would that even be possible?
You can't connect directly to the EC2 instance where the Heroku Postgres instance is running; it is managed by Heroku and normal users aren't allowed to connect to it.
If your application is running fine in Heroku, and you're running heroku pg:psql to attempt to connect to the DB, then most likely there is some issue with your local network that is preventing you from connecting to the Postgres database, like a firewall blocking outbound connections. Heroku Postgres databases are open to the public without any restriction on IP ranges.
It could be a problem with the proxy or firewall of the internet connection you are using.
Try to connect your PC to your mobile phone tethering and then launch the command again, just to verify if the problem lies there.
I was getting this kind of error when my pg_hba.conf or AWS security groups have not been configured properly. There are plenty of docs about how to resolve this. For example, you can check this list link
You can directly connect to EC2 Heroku Postgress instance by adding this attributes to the end of your DB connection url:
jdbc:postgresql://<host>/<dbname>?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory