# Running Console with a SQL database

**URL:** <https://forum.datomic.com/t/running-console-with-a-sql-database/853>\
**Category:** Troubleshooting\
**Created:** [February 21, 2019, 1:54pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853 "2019-02-21T13:54:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![infinitary](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/infinitary/32/267_2.png) [@infinitary](https://forum.datomic.com/u/infinitary)\
**Post date:** [February 21, 2019, 1:54pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/1 "2019-02-21T13:54:51Z")

</div>

I can’t connect the Console with a (local) SQL-backed database. The Console starts and shows the ‘hello’ database but after selecting it I’m getting a “Could not find hello//hello in catalog” exception in the Console log.

Any ideas on what should I be doing differently?

Thanks a lot!

* * *

To reproduce:

Install and start Postgres, create user and database:

```
CREATE ROLE sqluser LOGIN PASSWORD 'sqlpwd';
CREATE DATABASE sqldb WITH OWNER = sqluser TEMPLATE template0 ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' CONNECTION LIMIT = -1;

```

Prepare the ‘sqldb’ database for Datomic:

```
CREATE TABLE datomic_kvs (id text NOT NULL, rev integer, map text, val bytea, CONSTRAINT pk_id PRIMARY KEY (id)) WITH (OIDS = FALSE);
ALTER TABLE datomic_kvs OWNER TO sqluser; GRANT ALL ON TABLE datomic_kvs TO sqluser; GRANT ALL ON TABLE datomic_kvs TO public;

```

Prepare the transactor configuration:

```
protocol=sql
host=localhost
port=4334
license-key=....
sql-url=jdbc:postgresql://localhost:5432/sqldb
sql-user=sqluser
sql-password=sqlpwd
sql-driver-class=org.postgresql.Driver

```

Start the transactor:

```
transactor -Xmx4g $(pwd)/transactor.properties

```

Create the ‘hello’ database using repl:

```
(require '[datomic.api :as d])
(def db-uri "datomic:sql://hello?jdbc:postgresql://localhost:5432/sqldb")
(d/create-database db-uri)

```

Start the console

```
console -p 8080 dev datomic:sql://hello?jdbc:postgresql://localhost:5432/sqldb?user=sqluser\&password=sqlpwd
    Console started on port: 8080
    dev = datomic:sql://hello?jdbc:postgresql://localhost:5432/sqldb
    Open http://localhost:8080/browse in your browser (Chrome recommended)

```

Select the ‘hello’ database in the browser:

```
java.lang.RuntimeException: Could not find hello//hello in catalog
    at datomic.peer$get_connection$fn__10699.invoke(peer.clj:681)
    at datomic.peer$get_connection.invokeStatic(peer.clj:669)
    at datomic.peer$get_connection.invoke(peer.clj:666)
    at datomic.peer$connect_uri.invokeStatic(peer.clj:751)
    at datomic.peer$connect_uri.invoke(peer.clj:743)
    at clojure.lang.Var.invoke(Var.java:381)
    at datomic.Peer.connect(Peer.java:106)
    at datomic.api$connect.invokeStatic(api.clj:15)
    at datomic.api$connect.invoke(api.clj:13)
    at datomic.console$db.invokeStatic(console.clj:51)
    at datomic.console$db.invoke(console.clj:49)
    at datomic.console.BrowseUI$create_main_layout$db__1449.invoke(BrowseUI.clj:185)
    at datomic.console.BrowseUI$create_main_layout$fn__1509.invoke(BrowseUI.clj:337)
    at datomic.console.uihelp$add_vc$reify__587.valueChange(uihelp.clj:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
    at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1127)
    at com.vaadin.ui.AbstractField.setValue(AbstractField.java:542)
    at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:702)
    at com.vaadin.ui.ComboBox.changeVariables(ComboBox.java:664)
    at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396)
    at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:835)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
    at org.eclipse.jetty.server.Server.handle(Server.java:517)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
    at java.lang.Thread.run(Thread.java:748)
```

---

<div class="post-metadata">

**Author:** ![jaret](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/jaret/32/45_2.png) [@jaret](https://forum.datomic.com/u/jaret)\
**Post date:** [February 25, 2019, 2:13pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/2 "2019-02-25T14:13:01Z")

</div>

Hi @infinitary What version of Datomic Pro are you using here? After you create the DB at the REPL are you able to connect and transact using that URI?

```auto
(def conn (d/connect db-uri))

(def first-schema [{:db/ident :test/title
                           :db/valueType :db.type/string
                           :db/cardinality :db.cardinality/one
                           :db/doc "The title of a test"}])

@(d/transact conn first-schema)

```

Thanks,  
Jaret

---

<div class="post-metadata">

**Author:** ![infinitary](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/infinitary/32/267_2.png) [@infinitary](https://forum.datomic.com/u/infinitary)\
**Post date:** [February 25, 2019, 2:54pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/3 "2019-02-25T14:54:19Z")

</div>

Hi Jaret, thanks for the response. And fyi, I’m new to Datomic 🙂

My version is datomic-pro-0.9.5786.

I can connect to the database and transact with the Java shell using the URI “datomic:sql://hello?jdbc:postgresql://localhost:5432/sqldb?user=sqluser&password=sqlpwd”.

Another issue seems to be that I fail to connect from repl (creating worked, see above), when opening the URI (with or without ?user…) I get: ArityException Wrong number of args (1) passed to: api/eval229/fn–230/G–216–237 clojure.lang.AFn.throwArity (AFn.java:429).

Still, the database is up and I can transact/query it from the Java shell and also from my own Java app with the peer library.

---

<div class="post-metadata">

**Author:** ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)\
**Post date:** [February 25, 2019, 3:17pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/4 "2019-02-25T15:17:42Z")

</div>

Console should be started with a storage URI, not a specific database URI:  
[https://docs.datomic.com/on-prem/console.html#starting-the-console](https://docs.datomic.com/on-prem/console.html#starting-the-console)

(`bin/console -p port alias transactor-uri-without-db [alias transactor-uri-without-db]+`)

You are including your database name when you start console, thus the `hello//hello`

-Marshall

---

<div class="post-metadata">

**Author:** ![infinitary](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/infinitary/32/267_2.png) [@infinitary](https://forum.datomic.com/u/infinitary)\
**Post date:** [February 25, 2019, 3:30pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/5 "2019-02-25T15:30:14Z")

</div>

Thank you Marshall, sorry for not reading the doc properly.

However, starting the Console with

`console -p 8080 sql datomic:sql://localhost:4334/`

I get a “:db.error/invalid-sql-connection Must supply jdbc url in uri, or DataSource or Callable in protocolObject arg to Peer.connect trying to connect to datomic:sql://localhost:4334, make sure transactor is running” when trying to load the Console in the browser. The ‘sql’ word shows in Storage but the DB dropdown does not have any entries.

---

<div class="post-metadata">

**Author:** ![jaret](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/jaret/32/45_2.png) [@jaret](https://forum.datomic.com/u/jaret)\
**Post date:** [February 25, 2019, 4:25pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/6 "2019-02-25T16:25:52Z")

</div>

You still need to use a datomic URI, just leave off the db name.

---

<div class="post-metadata">

**Author:** ![infinitary](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/infinitary/32/267_2.png) [@infinitary](https://forum.datomic.com/u/infinitary)\
**Post date:** [February 25, 2019, 4:30pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/7 "2019-02-25T16:30:16Z")

</div>

Wow, cool, that could be one step closer…

`console -p 8080 sql datomic:sql://jdbc:postgresql://localhost:5432/sqldb?user=sqluser\&password=sqlpwd`

gives: “No suitable driver trying to connect to datomic:sql://jdbc:postgresql://localhost:5432/sqldb?user=sqluser&password=sqlpwd, make sure transactor is running”

PS: also happens if I manually add a postgres jar to the class path in the console launcher shell script  
PPS: same for all working combinations of “datomic:sql://localhost:4334/jdbc:postgresql://localhost:5432/sqldb?user=sqluser&password=sqlpwd”

---

<div class="post-metadata">

**Author:** ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)\
**Post date:** [February 25, 2019, 6:14pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/8 "2019-02-25T18:14:24Z")

</div>

I believe you still need the `?` in the URI (which separates db name from the storage address):

`datomic:sql://?jdbc:postgresql://localhost:5432/sqldb?user=sqluser&amp;password=sqlpwd`

---

<div class="post-metadata">

**Author:** ![infinitary](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/infinitary/32/267_2.png) [@infinitary](https://forum.datomic.com/u/infinitary)\
**Post date:** [February 26, 2019, 9:07am UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/9 "2019-02-26T09:07:36Z")

</div>

Thank you Marshall, indeed, that fixed it, Console runs against the local transactor that way 👍

Just one more thing, to connect the Console with a foreign installation I’d still need to add the transactor location into the URI - testing on the same configuration, on the localhost, extending the above URI to:

`datomic:sql://localhost:4334/?jdbc:postgresql://localhost:5432/sqldb?user=sqluser&amp;password=sqlpwd`

the Console loads but selecting the ‘hello’ database gives a “Could not find transactor:4334/hello in catalog” exception in the Console log. I can get by with the above already, but if I could make this URI work as well, life would be perfect again 😄

---

<div class="post-metadata">

**Author:** ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)\
**Post date:** [February 26, 2019, 2:07pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/10 "2019-02-26T14:07:56Z")

</div>

The database URI does not contain the transactor address. It is only the address to storage.  
The peer discovers the address of the active transactor by reading it from storage ([https://docs.datomic.com/on-prem/deployment.html#getting-connected](https://docs.datomic.com/on-prem/deployment.html#getting-connected)).

The URI you use to launch console should just be the remote storage URI (without a db name), regardless of where your transactor is running.

---

<div class="post-metadata">

**Author:** ![infinitary](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/infinitary/32/267_2.png) [@infinitary](https://forum.datomic.com/u/infinitary)\
**Post date:** [February 26, 2019, 3:49pm UTC](https://forum.datomic.com/t/running-console-with-a-sql-database/853/11 "2019-02-26T15:49:22Z")

</div>

Thank you soooo much, also for your patience 👼

Replacing `localhost` with the remote database host makes the Console connect to the remote installation. However, I had to make my remote transactor hostname resolve on my local machine via /etc/hosts so that the local Console could also reach it (when selecting the actual database in the user interface), but then it worked fine!

Thanks again!
