pgconf asia-201612203-pg reversi
TRANSCRIPT
![Page 1: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/1.jpg)
PGConf.ASIA Lightning Talk(2016-12-03)
pg_reversiぬこ@横浜 (@nuko_yokohama)
![Page 2: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/2.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/3.jpg)
3
The theme about today.
![Page 4: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/4.jpg)
4
Sorry, Useless knowledge
![Page 5: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/5.jpg)
5
Solutions for "Solitaire
employees"
![Page 6: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/6.jpg)
6
pg_reversi
![Page 7: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/7.jpg)
7
Reversi by PostgreSQL
![Page 8: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/8.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/9.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/10.jpg)
10
Viewer is implemented psql
script file.(Used PostgreSQL 9.6
feature “\crosstabview”)
![Page 11: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/11.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/12.jpg)
12
pg_reversi image
![Page 13: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/13.jpg)
13
pg_reversiDemonstration
![Page 14: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/14.jpg)
14
Able to play Reversi with psql!
![Page 15: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/15.jpg)
15
Up to this point is the explanation of the "Standard edition".
![Page 16: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/16.jpg)
16
pg_reversiEnterprise Edition
![Page 17: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/17.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/18.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/19.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/20.jpg)
20
Enterprise EditionDemonstration
![Page 21: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/21.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/22.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/23.jpg)
23
Exactly, feature for Exactly, feature for "Lazy employee in "Lazy employee in
Enterprise company".Enterprise company".
![Page 24: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/24.jpg)
24
Conclusion
![Page 25: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/25.jpg)
25
Reversi can also be played.
(It can not be used with pgAdmin4!)
![Page 26: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/26.jpg)
26
Only on the Only on the PostgreSQL….PostgreSQL….
![Page 27: Pgconf asia-201612203-pg reversi](https://reader031.vdocuments.site/reader031/viewer/2022021922/586f72821a28ab10258b542b/html5/thumbnails/27.jpg)
27
End.