Skip to content

Commit

Permalink
user mappring and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
m-thirumal committed Oct 24, 2024
1 parent 6ba08db commit ef7bc80
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions pgmodeler/foreign_data_wrapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ A foreign data wrapper is an extension available in PostgreSQL that allows you t

2. Create two function
1. Handler with name `postgres_fdw_handler` with
* Attribute
* Language - `c`
* Return method - `simple`
* Data type - `fwd_handler`
* Definition
* Symbol - `$libdir/postgres_fdw`
* Library - `postgres_fdw_handler`
* Disable `SQL` code
* Attribute
* Language - `c`
* Return method - `simple`
* Data type - `fwd_handler`
* Definition
* Symbol - `$libdir/postgres_fdw`
* Library - `postgres_fdw_handler`
* Disable `SQL` code

2. Validator with name `postgres_fdw_validator`
* Attribute
* Language - `c`
* Return method - `simple`
* Data type `void`
* Parameters
* Create parameter with
- name - p1
- type - text[]
* Create another parameter with
- name - p2
- type - oid
* Definition
* Symbol - `$libdir/postgres_fdw`
* Library - `postgres_fdw_validator`
* Disable `SQL` code
* Attribute
* Language - `c`
* Return method - `simple`
* Data type `void`
* Parameters
* Create parameter with
- name - p1
- type - text[]
* Create another parameter with
- name - p2
- type - oid
* Definition
* Symbol - `$libdir/postgres_fdw`
* Library - `postgres_fdw_validator`
* Disable `SQL` code


![Handler](./img/fwd/fwd_func_handler.png)
![Validator](./img/fwd/fwd_func_validator.png)

3. Create FDW (Foreign Data Wrapper), with the above created `handler` and `validator`.

* name `postgres_fdw`
* Select the above created `handler` fuction on the Handler & `vallidator` function on Validator dropdown
* Disable `SQL` code
* name `postgres_fdw`
* Select the above created `handler` fuction on the Handler & `vallidator` function on Validator dropdown
* Disable `SQL` code

![FWD](./img/fwd/fwd.png)

Expand All @@ -67,14 +67,14 @@ select * from pg_foreign_server;

![Foreign Server](./img/fwd/fwd_server.png)

5. Create `USER MAPPING`
5. Click on `USER MAPPING` and create new mapping

1. Select `server` and enter the user name and password in the options, with `key-value` pair

Select `server` and enter the user name and password in the options

```sql
user : fdw_user
password : thirumal
```
```sql
user : fdw_user
password : thirumal
```

Debug with following query

Expand All @@ -84,12 +84,12 @@ select * from pg_user_mapping

![User Mapping](./img/fwd/user_mapping.png)

6. Import or Create `foreign table`
6. Create (OR) Import `foreign table`

To import use the following SQL
`SQL` to import schema

```sql
IMPORT FOREIGN SCHEMA foreign_schema FROM SERVER foreign_server INTO public;
IMPORT FOREIGN SCHEMA foreign_schema FROM SERVER foreign_server INTO public;
```

Create `schema` with same name, if it's not available and create `foreign table`
Expand Down

0 comments on commit ef7bc80

Please sign in to comment.