# Error: undefined method \`to\_sym' for nil:NilClass for Postgres JDBC

**URL:** <https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390>\
**Category:** Logstash\
**Created:** [August 1, 2019, 6:32pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390 "2019-08-01T18:32:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ale\_Ksa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ale_ksa/32/45618_2.png) [@Ale\_Ksa](https://discuss.elastic.co/u/Ale_Ksa)\
**Post date:** [August 1, 2019, 6:32pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390/1 "2019-08-01T18:32:40Z")

</div>

Hello! I am getting an undefined method error when using Postgres JDBC in Logstash. [I've put the debug output on Pastebin.](https://pastebin.com/beNbwGNA)

And here is the config itself:

```auto
input {
	# pg_stat_database
	jdbc {
		jdbc_driver_library => ""
		jdbc_driver_class => "org.postgresql.Driver"
		jdbc_connection_string => "<redacted>"
		jdbc_user => "doadmin"
		jdbc_password => "<redacted>"
		statement => "SELECT * FROM pg_stat_database"
		type => "pg_stat_database"
	}
	
	# pg_stat_user_tables
	jdbc {
		jdbc_driver_library => ""
		jdbc_driver_class => "org.postgresql.Driver"
		jdbc_connection_string => "<redacted>"
		jdbc_user => "doadmin"
		jdbc_password => "<redacted>"
		statement => "SELECT * FROM pg_stat_user_tables"
		type => "pg_stat_user_tables"
	}
	
	# pg_stat_user_indexes
	jdbc {
		jdbc_driver_library => ""
		jdbc_driver_class => "org.postgresql.Driver"
		jdbc_connection_string => "<redacted>"
		jdbc_user => "doadmin"
		jdbc_password => "<redacted>"
		statement => "SELECT * FROM pg_stat_user_indexes"
		type => "pg_stat_user_indexes"
	}
}

output {
	elasticsearch {
		hosts => "http://localhost:9200"
		document_type => "%{type}"
		index => "pg_statistics"
	}
}

```

Due to another bug that got fixed today in upstream Git, I put the PostgreSQL JDBC .jar into logstash-core/lib/jars, hence the empty `jdbc_driver_library` in all three cases.

Can anyone help?

Thanks,  
Aleksa

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 1, 2019, 6:44pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390/2 "2019-08-01T18:44:17Z")

</div>

Hard to tell with a redacted connection string. [This](https://github.com/jeremyevans/sequel/blob/198c5cf66cc4459acaba43d1b5c051daf7053b3c/lib/sequel/database/connecting.rb#L26) is what the code is doing.

---

<div class="post-metadata">

**Author:** ![Ale\_Ksa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ale_ksa/32/45618_2.png) [@Ale\_Ksa](https://discuss.elastic.co/u/Ale_Ksa)\
**Post date:** [August 1, 2019, 7:08pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390/3 "2019-08-01T19:08:26Z")

</div>

Sorry, I thought that it too should be redacted. It is this:

```auto
elk-test-do-user-3713035-0.db.ondigitalocean.com

```

---

<div class="post-metadata">

**Author:** ![Ale\_Ksa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ale_ksa/32/45618_2.png) [@Ale\_Ksa](https://discuss.elastic.co/u/Ale_Ksa)\
**Post date:** [August 1, 2019, 7:38pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390/4 "2019-08-01T19:38:06Z")

</div>

Maybe I made some progress. I tried putting in the following as the connection string:

```auto
jdbc:postgresql://elk-test-do-user-3713035-0.db.ondigitalocean.com

```

And got this error:

```auto
 Error: Sequel::DatabaseError: driver.new.connect returned nil: probably bad JDBC connection string

```

Not sure how to proceed. The connection string looks right (though I may be wrong, ofc)

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 1, 2019, 7:39pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390/5 "2019-08-01T19:39:03Z")

</div>

> [@Ale\_Ksa](#):
>
> [elk-test-do-user-3713035-0.db.ondigitalocean.com](http://elk-test-do-user-3713035-0.db.ondigitalocean.com)

OK, so the code parses that as a URI, and then calls .to\_sym on the scheme. However, that URI does not have a scheme (http, https, etc.), so scheme is nil. That branch of the code is expecting a connection string like 'postgres://user:password@localhost/blog'. There is a lot more detail about what connection strings can look like [here](https://github.com/jeremyevans/sequel/blob/198c5cf66cc4459acaba43d1b5c051daf7053b3c/doc/opening_databases.rdoc). I have not used postgres, but for the DBs I am used to you would need a database name in the connection string.

---

<div class="post-metadata">

**Author:** ![Ale\_Ksa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ale_ksa/32/45618_2.png) [@Ale\_Ksa](https://discuss.elastic.co/u/Ale_Ksa)\
**Post date:** [August 1, 2019, 7:57pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390/6 "2019-08-01T19:57:31Z")

</div>

> [@Badger](#):
>
> I have not used postgres, but for the DBs I am used to you would need a database name in the connection string.

That was it! It looks like Postgres requires you to be connected to a database to be able to do anything. Here is the final connection string that seems to work (notice that I've specified a custom port):

```auto
jdbc:postgresql://elk-test-do-user-3713035-0.db.ondigitalocean.com/defaultdb

```

where `defaultdb` is, well, the default DB that can't be deleted.

@Badger, thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 29, 2019, 8:04pm UTC](https://discuss.elastic.co/t/error-undefined-method-to-sym-for-nil-nilclass-for-postgres-jdbc/193390/7 "2019-08-29T20:04:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
