2010-01-30 55 views
29

我之前询问过没有得到任何回复的question如何使用url连接到postgresql

基本上,当我尝试做heroku db:push时,得到一个错误invalid database url

我想我可以尝试明确提供数据库url。

我想:

heroku db:push postgres://[email protected]/myrailsdb

但是,这给了错误:

Failed to connect to database: 
    Sequel::DatabaseConnectionError -> PGError fe_sendauth: no password supplied 

什么是提供用户名和密码的格式?

回答

47

尝试heroku db:push postgres://username:[email protected]/myrailsdb

+0

如果你的本地数据库用户没有密码该怎么办? – mkirk 2011-11-15 04:13:37

+3

只需放下密码即'db push postgres:// username @ localhost/myrailsdb' – 2011-11-15 21:31:41

+1

如果没有提供密码,将会出现错误 无法连接到数据库: Sequel :: DatabaseConnectionError - > PGError fe_sendauth :没有提供密码 – user181677 2012-02-03 02:32:12

5

编辑您的postgresql配置(pg_hba.conf)文件并将'host'类型的方法更改为'trust'。但请注意,这并不安全。

# TYPE DATABASE  USER   ADDRESS     METHOD 

# "local" is for Unix domain socket connections only 
local all    all          trust 
# IPv4 local connections: 
host all    all    127.0.0.1/32   trust 
# IPv6 local connections: 
host all    all    ::1/128     md5 

重新启动你的PostgreSQL服务器并重新运行该命令

$ heroku db:push postgres://[email protected]/myrailsdb 

下面是引用我的回答:https://stackoverflow.com/a/7667344/181677

+0

其中pg_hba.conf文件位于何处? – kibaekr 2012-06-25 13:47:13

+0

其实,发现它。对于Ubuntu,Debian/Ubuntu:/etc/postgresql/9.0/main/pg_hba.conf – kibaekr 2012-06-25 14:01:28

8

这里是如何做到这一点的Ruby脚本:

# Connect to database. 
uri = URI.parse(ENV['DATABASE_URL']) 
postgres = PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password) 

# List all tables. 
tables = postgres.exec('SELECT * FROM pg_catalog.pg_tables') 
tables.num_tuples.times do |i| 
    p tables[i] 
end 
+0

你有什么进口/需求? – Nick 2014-10-24 13:13:17

+0

需要'uri'oops – Nick 2014-10-24 13:13:48

1

Heroku cli更改了命令。

heroku pg:push postgres://username:[email protected]/myrailsdb