2010-01-30 9 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

로컬 db 사용자에게 암호가없는 경우는 어떻게됩니까? – mkirk

+3

그냥 암호를 드롭, 즉'포스트 그레스를 밀어 DB : // 사용자 이름 @ localhost를/myrailsdb' –

+1

패스워드가 제공되지 않는 경우,이 데이터베이스에 연결하지 못했습니다 의 오류를 줄 것이다 : 속편을 :: DatabaseConnectionError -> PGError fe_sendauth : no password supplied – user181677

5

postgresql 구성 (pg_hba.conf) 파일을 편집하고 '호스트'유형 메소드를 '신뢰'로 변경하십시오. 그러나 이것이 안전하지 않다는 점에 유의하십시오.

# 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

+0

실제로 그것을 발견했습니다. 우분투 용, 데비안/우분투 : /etc/postgresql/9.0/main/pg_hba.conf – kibaekr

8
다음

루비 스크립트에서 그것을 할 방법은 다음과 같습니다

# 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

+0

에 'uri'가 필요합니다. – Nick

1

Heroku cli가 명령을 변경했습니다.

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