[Home]PostgreSql

ec2-34-238-138-162.compute-1.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic

...because I like languages that use CAPSLOCK!

Install postgresql:
   dnf install postgresql postgresql-jdbc


Configure network access for localhost:
    edit /var/lib/pgsql/data/pg_hba.conf

    # "local" is for Unix domain socket connections only [peer]
    local  all            all                                    trust
    host    all            all            127.0.0.1/32            trust
    host    all            all            ::1/128                trust

    "trust" effectively disables cryptographic authentication, PKI solution is probably preferable.


Start postgresql
   systemctl start postgresql

Create a database:
     createdb Testing
    psql Testing

     CREATE ROLE <myrole>;
    CREATE USER <username> WITH ROLE <myrole>;
    GRANT CONNECT ON DATABASE Testing TO <myrole>;
    GRANT SELECT ON TABLE <table> TO <myrole>;

     Note: Type \q to exit psql   

Create a table:
     CREATE TABLE Users (
        id    integer CONSTRAINT cannot_be_null NOT NULL,
        name  varchar(40) NOT NULL,
        UNIQUE(name)
    );

List tables in database:
     SELECT * FROM information_schema.tables WHERE table_schema = 'public';

Insert database:
     INSERT INTO Users (id,name) VALUES (123,'HELLO');

Jdbc:
        Include /usr/share/java/postgresql-jdbc.jar

        // Load class to register JDBC driver
        Class.forName("org.postgresql.Driver");

        Connection conn = DriverManager?.getConnection("jdbc:postgresql:Testing");
        Statement call = conn.createStatement();
        call.execute("SELECT * FROM Users;");

ec2-34-238-138-162.compute-1.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic
Edit this page | View other revisions | Recently used referrers
Last edited August 24, 2016 4:52 pm (viewing revision 1, which is the newest) (diff)
Search: