我正在尝试部署一个在Heroku上使用Postgresql的小型Dancer2应用程序。
到目前为止,我试图接近:
a)我输入了heroku addons:add heroku-postgresql
手工创建的所有表,并授予我在heroku数据库连接设置中找到的默认所有者的权限。然后我将以下连接设置添加到我的config.yml文件中:
DBIC:
d1ofgde:
dsn: 'dbi:Pg:dbname=d1ofgde'
user: 'ygcexhxtprm'
password: 'izU2xTVDfd5T5Byy4M4Xhk'
host: 'ec2-54-244-50-186.compute-1.amazonaws.com'
port: 5432
options:
RaiseError: 1
PrintError: 1
schema_class: 'My::Schema
这失败了。
b)我尝试使用以下命令在heroku上推送我的本地postgres数据库:
PGUSER=test PGPASSWORD=test heroku pg:push mytestdb DATABASE_URL postgres://ygcexmzlhxtprm:izU2xTVDfd5RekzT5Byy4M4Xhk@ec2-54-243-50-185.compute-1.amazonaws.com:5432/d1ofgdng49tf0e --app lit-mesa-10053
推手一个错误:
:pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of extension plpgsql
Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language
但是当我登录我的heroku postgres时,我看到了里面的桌子。
在这两种情况下,我在config.yml中为连接设置使用了相同的结构。并得到相同的错误消息:
2016-06-30T10:01:59.918775+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=lit-mesa-10053.herokuapp.com request_id=99195ea6-fb7e-488c-93e8-2b7b5e306432 fwd="89.122.156.100" dyno= connect= service= status=503 bytes=
2016-06-30T10:02:00.403773+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=lit-mesa-10053.herokuapp.com request_id=dae4956e-954c-498b-8a32-e8ef8dc01c43 fwd="89.122.156.100" dyno= connect= service= status=503 bytes=
2016-06-30T10:12:07.295999+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-30T10:12:14.677356+00:00 app[web.1]: Error while loading /app/app.psgi: The schema mytestdb is not configured at /app/local/lib/perl5/DBICx/Sugar.pm line 52, <DATA> line 1.
2016-06-30T10:12:14.677382+00:00 app[web.1]: Compilation failed in require at /app/app.psgi line 11, <DATA> line 1.
2016-06-30T10:12:15.886678+00:00 heroku[web.1]: Process exited with status 255
2016-06-30T10:12:20.228220+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=lit-mesa-10053.herokuapp.com request_id=36a8291d-fce1-485e-979c-986db9cbf9b7 fwd="89.122.156.100" dyno= connect= service= status=503 bytes=
答案 0 :(得分:0)
所以我用这段代码解决了我的错误:在myapp.pm中 我添加了这句话:
my $env_url = $ENV{MYAPP_DB_DSN};
my $env_user = $ENV{MYAPP_DB_USERNAME};
my $env_password = $ENV{MYAPP_DB_PASSWORD};
my $schema = My::Schema->connect("$env_url;user=$env_user;password=$env_password");
然后使用heroku config:set
我将值赋予
MyAPP_DB_DSN='dbi:Pg:dbname=mydb; host=myherokuhost'; port=5432'
MYAPP_DB_USERNAME=myusername
MYAPP_DB_PASSWORD=mypass
现在可以使用了