pgconf asia-201612203-pg reversi

27
PGConf.ASIA Lightning Talk (2016-12-03) pg_reversi ぬこ@横浜 (@nuko_yokohama)

Upload: toshi-harada

Post on 16-Apr-2017

243 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Pgconf asia-201612203-pg reversi

PGConf.ASIA Lightning Talk(2016-12-03)

pg_reversiぬこ@横浜 (@nuko_yokohama)

Page 2: Pgconf asia-201612203-pg reversi

2

Self-Introduction

Search with the word "PostgreSQL Ramen".

I'm "nuko_yokohama".I am aiming at PostgreSQL entertainer.

Page 3: Pgconf asia-201612203-pg reversi

3

The theme about today.

Page 4: Pgconf asia-201612203-pg reversi

4

Sorry, Useless knowledge

Page 5: Pgconf asia-201612203-pg reversi

5

Solutions for "Solitaire

employees"

Page 6: Pgconf asia-201612203-pg reversi

6

pg_reversi

Page 7: Pgconf asia-201612203-pg reversi

7

Reversi by PostgreSQL

Page 8: Pgconf asia-201612203-pg reversi

8

pg_reversi SQL Functions.

black(x, y)white(x,y)

black_pass()white_pass()

get_turn_boad_status()

Page 9: Pgconf asia-201612203-pg reversi

9

Implemented by Implemented by SQL/plpgsql.SQL/plpgsql.

Because, I do not want to Because, I do not want to implemented by implemented by

C language!C language!絶対に C言語で書きたくないでござる!

Page 10: Pgconf asia-201612203-pg reversi

10

Viewer is implemented psql

script file.(Used PostgreSQL 9.6

feature “\crosstabview”)

Page 11: Pgconf asia-201612203-pg reversi

11

Viewer script file.SELECT get_turn_boad_status() AS status;\o /dev/nullSELECT x AS " ", y, CASE WHEN status = 1 THEN '●' WHEN status = -1 THEN '○' ELSE ' ' END AS statusFROM boad ORDER BY x;\o\crosstabview " " y status y

Point. SELECT result output to /dev/null

Page 12: Pgconf asia-201612203-pg reversi

12

pg_reversi image

Page 13: Pgconf asia-201612203-pg reversi

13

pg_reversiDemonstration

Page 14: Pgconf asia-201612203-pg reversi

14

Able to play Reversi with psql!

Page 15: Pgconf asia-201612203-pg reversi

15

Up to this point is the explanation of the "Standard edition".

Page 16: Pgconf asia-201612203-pg reversi

16

pg_reversiEnterprise Edition

Page 17: Pgconf asia-201612203-pg reversi

17

FeaturesBy emit_log_hook, to conceal the SQL

log from pg_reversi application.static voidpg_reversi_emit_log_hook(ErrorData *data) { const char* appname = application_name;

if (appname == NULL || *appname == '\0') { /* applicatoin_name is no set */ return ; }

if (!strcmp(appname, "pg_reversi")) { /* When application_name is pg_reversi, output to the server log is suppressed. */ data->output_to_server = false; } return ;}

Page 18: Pgconf asia-201612203-pg reversi

18

Setting the pg_reversi to PostgreSQL setting "preload_shared_libraries'.

preload_shared_libraries = 'pg_reversi'

In psql not, use the "pg_reversi" utility (psql copy).

$ pg_reversi -U postgres pg_reversi

Page 19: Pgconf asia-201612203-pg reversi

19

Show “application_name”$ psql -U postgres pg_reversi -c "SHOW application_name" application_name ------------------ psql(1 row)

$ pg_reversi -U postgres pg_reversi -c "SHOW application_name" application_name ------------------ pg_reversi(1 row)

Page 20: Pgconf asia-201612203-pg reversi

20

Enterprise EditionDemonstration

Page 21: Pgconf asia-201612203-pg reversi

21

Standard Edition

Since SQL is output to the Since SQL is output to the server log, the DBA will server log, the DBA will

check it!check it!↓↓

My boss gets angry!My boss gets angry!

Page 22: Pgconf asia-201612203-pg reversi

22

Enterprise EditionSQL is not logged.SQL is not logged.

↓↓DBA and Boss also does DBA and Boss also does

not notice. not notice. Everyone is happy.Everyone is happy.

Win-Win!Win-Win!

Page 23: Pgconf asia-201612203-pg reversi

23

Exactly, feature for Exactly, feature for "Lazy employee in "Lazy employee in

Enterprise company".Enterprise company".

Page 24: Pgconf asia-201612203-pg reversi

24

Conclusion

Page 25: Pgconf asia-201612203-pg reversi

25

Reversi can also be played.

(It can not be used with pgAdmin4!)

Page 26: Pgconf asia-201612203-pg reversi

26

Only on the Only on the PostgreSQL….PostgreSQL….

Page 27: Pgconf asia-201612203-pg reversi

27

End.