Error: undefined method `to_sym' for nil:NilClass for Postgres JDBC

Hello! I am getting an undefined method error when using Postgres JDBC in Logstash. I've put the debug output on Pastebin.

And here is the config itself:

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

Hard to tell with a redacted connection string. This is what the code is doing.

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

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

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

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

And got this error:

 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)

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. I have not used postgres, but for the DBs I am used to you would need a database name in the connection string.

1 Like

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):

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!

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