# Using "pg" gem for ruby filter plugin

**URL:** <https://discuss.elastic.co/t/using-pg-gem-for-ruby-filter-plugin/242637>\
**Category:** Logstash\
**Created:** [July 26, 2020, 7:54am UTC](https://discuss.elastic.co/t/using-pg-gem-for-ruby-filter-plugin/242637 "2020-07-26T07:54:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayan\_Saha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayan_saha/32/72798_2.png) [@Ayan\_Saha](https://discuss.elastic.co/u/Ayan_Saha)\
**Post date:** [July 26, 2020, 7:54am UTC](https://discuss.elastic.co/t/using-pg-gem-for-ruby-filter-plugin/242637/1 "2020-07-26T07:54:49Z")

</div>

Hi, I am very new to logstash and facing problem when tried to use 'pg' in ruby filter plugin for sql query.  
This is my config file

```auto
    input {
        jdbc {
            # Postgres jdbc connection string to our database
            jdbc_connection_string => "jdbc:postgresql://localhost:26257/dev?user=root"

            # The user we wish to execute our statement as
            jdbc_user => "root"
       
            jdbc_validate_connection => true
            # The path to our downloaded jdbc driver
            jdbc_driver_library => ".\Downloads\postgresql-42.2.14.jar"
            # The name of the driver class for Postgresql
            jdbc_driver_class => "org.postgresql.Driver"

            # Schedule for input (after 1 minute)
            #schedule => "*/1 * * * *"

            # our query
            statement => "SELECT id, details::text from users"
        }
    }
     
    filter{
        json{
            source => "details"
        }
        mutate { remove_field => ["details"] }
        ruby {
            
            path => "test.rb"
            
        }
    }

    output {
        
        stdout{
            codec => rubydebug
        }
       
    }

```

this is the external ruby file i am using -

```auto
    require 'pg'

    def filter(event)
        conn = PG.connect(
            user: 'root',
            dbname: 'dev',
            host: 'localhost',
            port: 26257,
            sslmode: 'disable'
        )

        ### sql queries and operations

        #####
        return [event]
    end

```

executing this configuration throwing this error -\>

```auto
[2020-07-26T13:21:39,676][ERROR][logstash.agent] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"Java::JavaLang::IllegalStateException", :message=>"Unable to configure plugins: (LoadError) no such file to load -- pg", 

```

---

<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 23, 2020, 7:54am UTC](https://discuss.elastic.co/t/using-pg-gem-for-ruby-filter-plugin/242637/2 "2020-08-23T07:54:53Z")

</div>

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