Package org.h2.server.pg

# Class PgServer

java.lang.Object
org.h2.server.pg.PgServer

All Implemented Interfaces:
  `Service`

public class PgServer extends Object implements Service
This class implements a subset of the PostgreSQL protocol as described here: https://www.postgresql.org/docs/devel/protocol.html The PostgreSQL catalog is described here: https://www.postgresql.org/docs/7.4/catalogs.html

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_PORT`
The default port to use for the PG server.
`static final int`
`PG_TYPE_BOOL`
`static final int`
`PG_TYPE_BPCHAR`
`static final int`
`PG_TYPE_BYTEA`
`static final int`
`PG_TYPE_DATE`
`static final int`
`PG_TYPE_FLOAT4`
`static final int`
`PG_TYPE_FLOAT8`
`static final int`
`PG_TYPE_INT2`
`static final int`
`PG_TYPE_INT2_ARRAY`
`static final int`
`PG_TYPE_INT4`
`static final int`
`PG_TYPE_INT4_ARRAY`
`static final int`
`PG_TYPE_INT8`
`static final int`
`PG_TYPE_NUMERIC`
`static final int`
`PG_TYPE_TEXT`
`static final int`
`PG_TYPE_TIME`
`static final int`
`PG_TYPE_TIMESTAMP`
`static final int`
`PG_TYPE_TIMESTAMPTZ`
`static final int`
`PG_TYPE_TIMETZ`
`static final int`
`PG_TYPE_UNKNOWN`
`static final int`
`PG_TYPE_VARCHAR`
The VARCHAR type.
`static final int`
`PG_TYPE_VARCHAR_ARRAY`

## Constructor Summary

Constructors
Constructor
Description
`PgServer()`

## Method Summary

Modifier and Type
Method
Description
`String`
`checkKeyAndGetDatabaseName(String db)`
If no key is set, return the original database name.
`static int`
`convertType(TypeInfo type)`
Convert the SQL type to a PostgreSQL type
`static String`
`formatType(int pgType)`
Returns the name of the given type.
`boolean`
`getAllowOthers()`
Check if remote connections are allowed.
`String`
`getName()`
Get the human readable name of the service.
`int`
`getPort()`
Gets the port this service is listening on.
`String`
`getType()`
Get the human readable short name of the service.
`String`
`getURL()`
Get the URL of this service in a human readable form
`void`
`init(String... args)`
Initialize the service from command line options.
`boolean`
`isDaemon()`
Check if a daemon thread should be used.
`boolean`
`isRunning(boolean traceError)`
Check if the service is running.
`void`
`listen()`
Listen for incoming connections.
`void`
`start()`
Start the service.
`void`
`stop()`
Stop the service.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_PORT

public static final int DEFAULT_PORT
The default port to use for the PG server. This value is also in the documentation and in the Server javadoc.

See Also:
  - Constant Field Values

### PG_TYPE_VARCHAR

public static final int PG_TYPE_VARCHAR
The VARCHAR type.

See Also:
  - Constant Field Values

### PG_TYPE_BOOL

public static final int PG_TYPE_BOOL

See Also:
  - Constant Field Values

### PG_TYPE_BYTEA

public static final int PG_TYPE_BYTEA

See Also:
  - Constant Field Values

### PG_TYPE_BPCHAR

public static final int PG_TYPE_BPCHAR

See Also:
  - Constant Field Values

### PG_TYPE_INT8

public static final int PG_TYPE_INT8

See Also:
  - Constant Field Values

### PG_TYPE_INT2

public static final int PG_TYPE_INT2

See Also:
  - Constant Field Values

### PG_TYPE_INT4

public static final int PG_TYPE_INT4

See Also:
  - Constant Field Values

### PG_TYPE_TEXT

public static final int PG_TYPE_TEXT

See Also:
  - Constant Field Values

### PG_TYPE_FLOAT4

public static final int PG_TYPE_FLOAT4

See Also:
  - Constant Field Values

### PG_TYPE_FLOAT8

public static final int PG_TYPE_FLOAT8

See Also:
  - Constant Field Values

### PG_TYPE_UNKNOWN

public static final int PG_TYPE_UNKNOWN

See Also:
  - Constant Field Values

### PG_TYPE_INT2_ARRAY

public static final int PG_TYPE_INT2_ARRAY

See Also:
  - Constant Field Values

### PG_TYPE_INT4_ARRAY

public static final int PG_TYPE_INT4_ARRAY

See Also:
  - Constant Field Values

### PG_TYPE_VARCHAR_ARRAY

public static final int PG_TYPE_VARCHAR_ARRAY

See Also:
  - Constant Field Values

### PG_TYPE_DATE

public static final int PG_TYPE_DATE

See Also:
  - Constant Field Values

### PG_TYPE_TIME

public static final int PG_TYPE_TIME

See Also:
  - Constant Field Values

### PG_TYPE_TIMETZ

public static final int PG_TYPE_TIMETZ

See Also:
  - Constant Field Values

### PG_TYPE_TIMESTAMP

public static final int PG_TYPE_TIMESTAMP

See Also:
  - Constant Field Values

### PG_TYPE_TIMESTAMPTZ

public static final int PG_TYPE_TIMESTAMPTZ

See Also:
  - Constant Field Values

### PG_TYPE_NUMERIC

public static final int PG_TYPE_NUMERIC

See Also:
  - Constant Field Values

## Constructor Details

### PgServer

public PgServer()

## Method Details

### init

public void init(String... args)
Description copied from interface: `Service`
Initialize the service from command line options.

Specified by:
  `init` in interface `Service`
Parameters:
  `args` - the command line options

### getURL

public String getURL()
Description copied from interface: `Service`
Get the URL of this service in a human readable form

Specified by:
  `getURL` in interface `Service`
Returns:
  the url

### getPort

public int getPort()
Description copied from interface: `Service`
Gets the port this service is listening on.

Specified by:
  `getPort` in interface `Service`
Returns:
  the port

### start

public void start()
Description copied from interface: `Service`
Start the service. This usually means create the server socket. This method must not block.

Specified by:
  `start` in interface `Service`

### listen

public void listen()
Description copied from interface: `Service`
Listen for incoming connections. This method blocks.

Specified by:
  `listen` in interface `Service`

### stop

public void stop()
Description copied from interface: `Service`
Stop the service.

Specified by:
  `stop` in interface `Service`

### isRunning

public boolean isRunning(boolean traceError)
Description copied from interface: `Service`
Check if the service is running.

Specified by:
  `isRunning` in interface `Service`
Parameters:
  `traceError` - if errors should be written
Returns:
  if the server is running

### getAllowOthers

public boolean getAllowOthers()
Description copied from interface: `Service`
Check if remote connections are allowed.

Specified by:
  `getAllowOthers` in interface `Service`
Returns:
  true if remote connections are allowed

### getType

public String getType()
Description copied from interface: `Service`
Get the human readable short name of the service.

Specified by:
  `getType` in interface `Service`
Returns:
  the type

### getName

public String getName()
Description copied from interface: `Service`
Get the human readable name of the service.

Specified by:
  `getName` in interface `Service`
Returns:
  the name

### formatType

public static String formatType(int pgType)
Returns the name of the given type.

Parameters:
  `pgType` - the PostgreSQL type oid
Returns:
  the name of the given type

### convertType

public static int convertType(TypeInfo type)
Convert the SQL type to a PostgreSQL type

Parameters:
  `type` - the SQL type
Returns:
  the PostgreSQL type

### checkKeyAndGetDatabaseName

public String checkKeyAndGetDatabaseName(String db)
If no key is set, return the original database name. If a key is set, check if the key matches. If yes, return the correct database name. If not, throw an exception.

Parameters:
  `db` - the key to test (or database name if no key is used)
Returns:
  the database name
Throws:
  `DbException` - if a key is set but doesn't match

### isDaemon

public boolean isDaemon()
Description copied from interface: `Service`
Check if a daemon thread should be used.

Specified by:
  `isDaemon` in interface `Service`
Returns:
  true if a daemon thread should be used