在 lein ring 服务器之后,我收到错误 PSQLException no password was provided

after lein ring server, I get error PSQLException no password was provided

我对 Postgres 和 clojure 很天真

我想运行这个https://gitlab.com/dzaporozhets/clojure-picture-gallery

Install

git clone https://gitlab.com/clojure-code-examples/picture-gallery.git
cd picture-gallery

# Install dependencies
lein deps

# Create database
psql -c 'CREATE DATABASE gallery TEMPLATE template0'

Running

To start a web server for the application, run:

lein ring server

这是我必须要做的过程。 1)) 我不得不 git 克隆但是 git 克隆没有用。他们想让我输入 ID、密码。像这样:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\jiji>git clone https://gitlab.com/clojure-code-examples/picture-gallery
.git
Cloning into 'picture-gallery'...
Username for 'https://gitlab.com': ji
Password for 'https://ji@gitlab.com':
fatal: Authentication failed for 'https://gitlab.com/clojure-code-examples/pictu
re-gallery.git/'

C:\Users\jiji>

无论如何我从网上下载了源码并解压了这个文件

2) 我写 psql -c 'CREATE DATABASE gallery TEMPLATE template0' 时遇到问题。我使用 Windows 7. 虽然我安装了 postgresql,但 'psql' 指令在 cmd window 中不起作用。我不知道如何在 window 中使用 'psql' 指令。反正我是这样制作画廊数据库的

3) 然后我在 cmd 中写了 lein ring server window 但我得到这样的错误:

C:\Users\jiji\clojureproject\clojure-picture-gallery-master>lein ring server
picture-gallery is starting
Exception in thread "main" org.postgresql.util.PSQLException: The server request
ed password-based authentication, but no password was provided., compiling:(C:\U
sers\jiji\AppData\Local\Temp\form-init366034846235691962.clj:1:105)
        at clojure.lang.Compiler.load(Compiler.java:7142)
        at clojure.lang.Compiler.loadFile(Compiler.java:7086)
        at clojure.main$load_script.invoke(main.clj:274)
        at clojure.main$init_opt.invoke(main.clj:279)
        at clojure.main$initialize.invoke(main.clj:307)
        at clojure.main$null_opt.invoke(main.clj:342)
        at clojure.main$main.doInvoke(main.clj:420)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:383)
        at clojure.lang.AFn.applyToHelper(AFn.java:156)
        at clojure.lang.Var.applyTo(Var.java:700)
        at clojure.main.main(main.java:37)
Caused by: org.postgresql.util.PSQLException: The server requested password-base
d authentication, but no password was provided.
        at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(Connect
ionFactoryImpl.java:473)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Conne
ctionFactoryImpl.java:203)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactor
y.java:65)
        at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Conn
ection.java:146)
        at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Conn
ection.java:35)
        at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gC
onnection.java:22)
        at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Conn
ection.java:47)
        at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:30)
        at org.postgresql.Driver.makeConnection(Driver.java:414)
        at org.postgresql.Driver.connect(Driver.java:282)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:208)
        at clojure.java.jdbc$get_connection.invoke(jdbc.clj:177)
        at clojure.java.jdbc$get_connection.invoke(jdbc.clj:161)
        at clojure.java.jdbc$get_connection.invoke(jdbc.clj:164)
        at clojure.java.jdbc$with_connection_STAR_.invoke(jdbc.clj:300)
        at picture_gallery.models.schema$table_exists_QMARK_.invoke(schema.clj:2
8)
        at picture_gallery.models.schema$migrate.invoke(schema.clj:35)
        at picture_gallery.handler$init.invoke(handler.clj:18)
        at clojure.lang.Var.invoke(Var.java:375)
        at ring.server.standalone$serve.doInvoke(standalone.clj:93)
        at clojure.lang.RestFn.invoke(RestFn.java:423)
        at ring.server.leiningen$serve.invoke(leiningen.clj:20)
        at user$eval6633.invoke(form-init366034846235691962.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:6703)
        at clojure.lang.Compiler.eval(Compiler.java:6693)
        at clojure.lang.Compiler.load(Compiler.java:7130)
        ... 11 more
Subprocess failed

C:\Users\jiji\clojureproject\clojure-picture-gallery-master>

估计是密码问题。但我不知道这是什么意思

简而言之,我有关于 1)),2)),3)) 三个问题,为什么它们不起作用?

问题 3) 的答案

看看/src/picture_gallery/models/db.clj这里https://gitlab.com/dzaporozhets/clojure-picture-gallery/blob/master/src/picture_gallery/models/db.clj#L4

要么设置你的 DATABASE_URL 环境变量以包含有效的 postgres 连接 url 要么只使用

(def db (or (System/getenv "DATABASE_URL")
            "postgresql://user:password@localhost:5432/gallery")) 

@localhost 之前的 userpassword 替换为您的 postgres 用户和密码