Using "pg" gem for ruby filter plugin

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

    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 -

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

[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", 

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