本文介绍了从Google Colab连接到Postresql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的Google Colab连接到我的Postgres数据库。当我尝试从Jupyter Notebook连接到它时,它正在工作,因此我猜测我的凭据很好。这是我得到的错误:
I am trying to connect my Google Colab to my Postgres DB. When I try to connect to from Jupyter Notebook it's working, so I'm guessing that my credentials are fine. This is the error that I got:
服务器本地运行并在Unix域套接字上接受
连接 /var/run/postgresql/.s.PGSQL.5432?
Is the server running locally and acceptingconnections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我该如何解决?我的Postgres在我的机器上运行。
How can I solve it? My Postgres running on my machine.
谢谢!
推荐答案
您还可以安装PostgreSQL
You can also install PostgreSQL in Colab.
# install
!apt install postgresql postgresql-contrib &>log
!service postgresql start
!sudo -u postgres psql -c "CREATE USER root WITH SUPERUSER"
# set connection
%load_ext sql
%config SqlMagic.feedback=False
%config SqlMagic.autopandas=True
%sql postgresql+psycopg2://@/postgres
然后您可以使用%sql
或 %% sql
magic
Then you can query using %sql
or %%sql
magic
df = %sql SELECT * FROM pg_catalog.pg_tables
df
这篇关于从Google Colab连接到Postresql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!