I am following this tutorial to upload my existing Django project running locally on sqlite to Google Cloud Run / Postgres.
I have the cloud_sql_proxy service running and can sign into Postgres from the command line.
I am at the point of running the command
python manage.py migrate
And I get the error:
django.db.utils.OperationalError: connection to server on socket "/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
The answer to that questions is Yes, the server is running locally and accepting connections because I can log in with the Postgres client:
agerson#agersons-iMac ~ % psql "sslmode=disable dbname=postgres user=postgres hostaddr=127.0.0.1"
Password for user postgres:
psql (14.1, server 13.4)
Type "help" for help.
postgres=>
I double checked the connection string in my .env file and it has the correct UN / P
Is this scoket not getting created somehow in a previous step?
/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432
It looks like there's a mismatch between what the app is looking for and how you're launching the proxy. The error explains the problem.
You're launching the proxy like this with an incorrect region name (us-central):
cloud_sql_proxy -instances="cgps-registration-2:us-central:cgps-reg-2-postgre-sql=tcp:5432
But the app is looking for us-central1. Try this (omitting the =tcp:5432 to create a Unix socket):
cloud_sql_proxy -instances="cgps-registration-2:us-central1:cgps-reg-2-postgre-sql
I have installed pgadmin on a new windows laptop and when I try to create a new server, it says:
When I try to run my django app in pycharm it is giving me the same 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?
How to solve this ?
In case someone is running the pgadmin-4 in docker, and not able to connect to postgres container, like me.
The solution is to first find the ip at which the docker image is running.
Step-1, make sure the postgres container is running.
Step-2 write command- PS C:\docker> docker ps
Should result as below or similar,
Step3- in order to find the ip address running the postgres use part of container ID and analyze like below command
PS C:\docker> docker inspect fc834
Note: Here I have only used part of container id that is fc834..
This should result the following or similar,
Step4-
Use this ip address in the connection as below with your correct username and password
You may need to installing PostgreSQL Server first.
You can verify if the folder is created in the below folder,
C:\Program Files\PostgreSQL
You can configurate your newly created server to run on localhost and port 5432.
First select the “Connection” tab in the “Create-Server” window. Then, configure the connection as follows:
Enter your server’s IP address in the “Hostname/ Address” field. Default is localhost.
Specify the “Port” as “5432”.
Enter the name of the database in the “Database Maintenance” field.
Enter your username as postgres and password (use the same password you used when previously configuring the server to accept remote connections) for the database.
Click “Save” to apply the configuration.
NOTE You first have to install PostgreSQL on your machine and run it or run it with docker.
I had the same issue. But in my case I had installed pgadmin in version 9. But also installed version 12 at the same time.
When I now uninstalled version 9, the port was already set in the config of version 12 and not given free.
So my solution was to change the port of version 12 in the postgresql.conf file. Or even simplier, change the port in the server creation from 5432 to 5433. Now you are able to create a server again.
You should uninstall Postgres and pgAdmin from your PC. Then install postgres, note that you have the option of installing pgAdmin together with Postgres, so you don't have to download pgAdmin separately. Allow the installation to complete then restart you PC. Hopefully you should be able to create your server/database
I was running postgress and pgadmin both using docker container.
sudo docker ps
sudo docker inspect <postgress_container_id>
Output:
"Networks": {
"work_file_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"postgres",
"578a7a1050d1"
],
"NetworkID": "49dbe9d7280b55e36afc4308469c1b55e051d7eea8f1c03f08728e652cf22b5b",
"EndpointID": "c30a642c5a0f2970147c9734cadfbe1e8d7c29fcba8a83a628b7c2b3db114716",
"Gateway": "172.18.0.1",
**"IPAddress": "172.18.0.4",**
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:04",
"DriverOpts": null
}
Instead of localhost put the IP obtained from above command (172.18.0.4)
In my case was I got both pgadmin and postgresql services running in separate docker containers and I was trying to connect to localhost(127.0.0.1), which is cause of unable to connect to server error.
Note: 5438 port on my computer (host machine) was mapped to 5432 port of postgresql container.
so practically there are two solutions (if you have these services in separate containers and you have mapped postgresql port to your host machine ):
1-find out your local IP (mine is 192.168.1.106) and put it in the Host field.
2- you can put two containers(pgadmin and postgres) in one network (docker network)
and instead of your local IP, put postgres container IP in the Host field.
-Another tip that may help: what I've recently find out was if you are linux user and have ufw enabled, you should allow the port.
e.g. on my computer postgres is running on 5438 port, so I performed below command (so I could connect from pgadmin container to 5438 port of host wich postgres is running)
ufw allow 5438
Execute the container with the data Eg:
docker run --name postgresdb -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password -e POSTGRES_DB=mydb -p 5432:5432 --restart always -d postgres
Then in the PGAdmin client in the Host Name/Address use:
host.docker.internal
Image Conn PGAdmin
I was trying to install PostgreSQL and pgAdmin with an installer that is given here https://www.postgresql.org/download/windows/. This installer includes the PostgreSQL server, pgAdmin;
I was facing an error while starting pgAdmin: "The pgAdmin 4 server could not be contacted". I tried different solutions but did not work.
Then I uninstalled both of them, deleted the temp folder C:\Users\%USERNAME%\AppData\Roaming\pgAdmin and delete those ones too %temp%.
Then I installed the pgAdmin separately from this link https://www.pgadmin.org/download/
and it works. If you need to connect it with your local server I think you should install the PostgreSQL server first and then pgAdmin separately.
I faced the same problem. So I uninstalled pgAdmin through control panel. after that deleted the folder where pgAdmin was located. Then I went to this link and installed pgadmin whole package from there and now it works fine.
I was getting this error when I was running pgadmin in a docker container on my machine, which meant that localhost:5432 was not accessible.
I worked around this by using the native version of pgadmin.
If you are running PostgreSQL in a docker container, set the host name in pgAdmin to postgres not the mapped address or localhost.
press win key+R then Search for services.msc A window will open in that find postgresql-x64-13 right click, in that tab click start option For me its works perfectly.
Check out this stackoverflow link
unable to connect to server for Postgres
how I solved this problem in ubuntu 22.04
I didn't have a password set in Postgres, that's why the error occurred 'unable to connect server 127.0.0.0 port 5432
Open the terminal in ubuntu and enter this command;
sudo -u postgres psql
Run the statement to add new password. ALTER USER Postgres PASSWORD 'AddNewPasswordHere'; in '' you should enter your new password
Example:
1)sudo -u postgres psql
2)ALTER USER postgres PASSWORD 'mynewpassword'
3)sudo service postgresql restart
4)Then you can create a server in pgadmin
If you already tried with “127.0.0.1” and it didn’t work then use “localhost”
After two years i think this would be of good help to so many people.
You don't have to uninstall postgresql or PGADMIN from your system.
What you need to do i input the username and password for a particular user created on postgresql into the server input box.
And that all you need.
i hope this helps anyone
I am currently successfully using Ansible to run tasks on hosts that are in a private subnet in AWS, which the below group_vars is setting up:
ansible_ssh_common_args: '-o ProxyCommand="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -W %h:%p -q ec2-user#bastionhost#example.com"'
This is working fine.
For Windows instances not in a private subnet the following group_vars works:
---
ansible_user: "AnsibleUser"
ansible_password: "Password"
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
Now, trying to get Ansible to deploy to a Windows server behind the bastion by just using the ProxyCommand won't work - which I understand.
I believe though that there is a new protocol/module I can use called psrp.
I imagine that my group_vars for my Windows hosts needs to change to something like this:
---
ansible_user: "AnsibleUser"
ansible_password: "Password"
ansible_port: 5986
ansible_connection: psrp
ansible_psrp_cert_validation: ignore
If I run with just the above changes against instances that are publicly available (and not trying to connect via a bastion), my task seems to work fine:
Using module file /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/modules/windows/win_shell.ps1
<10.100.11.14> ESTABLISH PSRP CONNECTION FOR USER: Administrator ON PORT 5986 TO 10.100.11.14
PSRP: EXEC (via pipeline wrapper)
I know there must be more changes before I can try this on a windows server behind a bastion, but ran it anyway to see what errors I get to give me clues on what to do next. Here is the result when running this on an instance behind a bastion server:
Using module file /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/modules/windows/setup.ps1
<10.100.11.14> ESTABLISH PSRP CONNECTION FOR USER: Administrator ON PORT 5986 TO 10.100.11.14
The full traceback is:
.
.
.
.
ConnectTimeout: HTTPSConnectionPool(host='10.100.11.14', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x110bbfbd0>, 'Connection to 10.100.11.14 timed out. (connect timeout=30)'))
It seems like Ansible is ignoring my group_vars for the ProxyCommand - which I'm not sure if that's expected.
I'm also not sure on what the next steps are to enable Ansible to deploy to Windows servers behind a bastion.
What config am I missing?
The doc says, the ansible_ssh_common_args setting is appended to sftp, scp, and ssh commands. So it sounds normal to me that is not taking into account when using winrm or psrp ansible_connection.
As explained in the link provided by Pouyan in the comments, ansible_psrp_proxy variable will be used to provide proxy information.
ansible_connection: psrp
ansible_psrp_proxy=socks5h://localhost:1234
More info on the creation of the socks proxy can be found on: https://www.bloggingforlogging.com/2018/10/14/windows-host-through-ssh-bastion-on-ansible/
I'm trying to set up an SSH tunnel to access my server (currently an ubuntu 16.04 VM on Azure) to set up safe access to my django applications running on it.
I was able to imitate the production environment with Apache WSGI and it works pretty good but since I'm trying to develop the application I don't want to make it available to broader public right now - but to make it visible only for a bunch of people.
To the point: when I set up the ssh tunnel using putty on Windows 10 (8000 to localhost:8000) and I run http://localhost:8000/ I get the folowing error:
"Not Found HTTP Error 404. The requested resource is not found.".
How can I make it work? I run the server using manage.py runserver 0:8000.
I found somewhere that the error may be due to the fact that the application does not have access to ssh files, but I don't know whether that's the point here (or how to change it).
Regards,
Dominik
After hours of trying I was able to solve the problem.
First of all, I made sure putty connects to the server and creates the desired tunnel. To do that I right-clicked on the putty window (title bar) and clicked event log. I checked the log and found the following error:
Local port 8000 forwarding to localhost:8000 failed: Network error:
Permission denied
I was able to solve it by choosing other local port (9000 instead of 8000 in my instance).
Second of all, I edited the sshd_config file: sudo vi etc/ssh/sshd_config
and added these three lines:
AllowAgentForwarding yes
AllowTcpForwarding yes
GatewayPorts yes
I saved the file and restarted the ssh service:
sudo service ssh stop
sudo service ssh start
Now when I visit localhost:9000 everything works just fine.
Im pulling my hair out with this one. I've managed to get a site running on Digital Ocean through Forge and also SSH into the server so I know that the SSH keys are setup correctly.
But when trying to connect via Navicat, I keep getting the error "Unable to load key". Does anyone know what this is in reference to or what the problem is.
regards
There is an answer from 2015 on Navicat forum, indicating there could be issue with ssh key support.
If you can connect via ssh, do an ssh tunnel to your server manually:
ssh -v servername -L 3306:127.0.0.1:3306 -N
Afterwards, you connect to remote mysql as it was on your localhost (you should not have one running on 3306, otherwise map to another local port)